Programmatically insert hierarchical terms & set terms for post causes glitch? [duplicate]

I am inserting an array of terms into my custom taxonomy programmatically. Some terms have parents/children. After each term has been entered, I then insert an array of posts into my custom post type. After inserting each post, I then set each post to it’s proper taxonomy terms (parent terms and child terms).

After that entire sequence completes, when I navigate to the custom taxonomy management page. (Ex: ./edit-tags.php?taxonomy=my_custom_taxonomy&post_type=my_custom_post_type) It only shows the parent terms, with the number of posts in those parent terms.

None of the child terms show up.

If I edit a post from the custom post type, it shows that it has the proper parent/child terms selected.

Here’s the strange part. If I edit one of the parent terms from the taxonomy management page and don’t change anything, just click update. All of the sudden, all of my parent and children terms show up correctly.

It seems like WordPress should be flushing all these cached items automatically when these tasks are executed, but it’s not.

Is this a WordPress bug? Am I doing something wrong, or forgetting to do something?

1 Answer
1

I asked the same question a while ago. Scribu gave me an answer here.

The long and short of it: after you insert your terms, add this line of code.

delete_option("my_custom_taxonomy_children");

Of course, replace my_custom_taxonomy with your own, but leave the _children part.

Leave a Comment