Ask your WordPress questions! Pay money and get answers fast! (more info)

Pre-populate a hierarchical taxonomy - upto four levels WordPress



Im trying to pre-populate a custom taxonomy with regions, but am having trouble handling the multi dimensional array required for a hierarchical category.

At the moment I have a simple plugin that creates the taxonomy (loosely based on:

The listing I would like to create looks something like:

- US
-- North East
--- State
--- State
--- State
- North West
--- State
--- State
--- State
- International
-- North America
--- Canada
--- Mexico
-- Europe
--- UK
---- England
---- Scotland
---- Wales
--- Country
--- Country

If your code it was built upon a plugin like the git example, that would make it easier for me to test.

An example array that could generate the above example
A function that iterates over this array and
- Check that the entry does not already exist
- Add the entries to the taxonomy under the appropriate parent

Also, multidimensional arrays can be tricky (which is why I'm here) so if you want to recommend a different approach im open as long as it is easy to read and and concise.

I've been looking at the following plugin example for a flat list (git example post):

And have noted this SE topic about a WP caching bug when inputting a hierarchical taxonomy

Answers (1)


Bob answers:

I have modified a plugin please check it.

[[LINK href=""]][[/LINK]]

Please note you should first delete old texonomy created by the old plugin.
Let me know if you have any trouble.


Bob comments:

Attaching image of output of above plugin.