This certainly looks like a bug to me.
I put together the following code for you to test it on a fresh install.
Basically, the code will add two sub categories under the “uncategorized” to achieve the following effect

uncategorized
   sub-uncategorized
       sub-sub-uncategorized

No problems with adding them to the wp_terms and wp_term_taxonomies.
Both Parent ID’s are properly added.

The problem is in the wp admin ui.
You only see the uncategorized and the sub-uncategorized. The last one ( sub-sub ) is missing in action!

But if you go to the parent dropdown selection on the very same “add categories” page, you will see that both the sub-uncat” and the “sub-sub-cat” appears there, properly indented – appearing exactly in the following correct hierarchy

uncategorized
   sub-uncategorized
       sub-sub-uncategorized

To bring the missing sub-sub-cat into the main view, you have to do one of the following steps;

you either recycle the wp by stopping and starting.

or simply add a dummy cat and then click on the “categories” link to list all cats. then wp remembers to display the subs properly.

Anyone has any idea why this is happening?

I’d appreciate any programmatic remedies so that I don’t have to go thru the silly steps t just to get the cats into view.

The code is below. Just adjust the wp-load.php path accordingly before you can test it on a fresh install and then check what I described above for yourself.

<?php

error_reporting (E_ALL);

//load the wp shebang into this page
include (" put the full path here to the wp-load.php");


define('WP_USE_THEMES', false);


//add a sub category under the "uncategorized" that fresh install comes with
$Term = "Sub-UnCategorized";
$args = array('parent' => 1 );
wp_insert_term($Term, "category", $args);


//add another sub under the recentyl created above. 
$Term = "Sub-Sub-UnCategorized";
$args = array('parent' => 3 );
wp_insert_term($Term, "category", $args);

echo "<pre>

After running this code, you will notice that the Sub-Sub-UnCategorized is missing from the view. 

But what's funny is the dropdown. 
Check the dropdown for the *parent* selection, you will see that the missing
Sub-Sub-UnCategorized is there. 

In order to get the missing sub-sub into the view, you will have to do two things. 

1 - Add a dummy cat.
2 - Click on the categories link on the admin navigation.

With that, wp will sort this problem out and you will see everything you should have.

I cannot figure out what's causing this behavior and how to remedy this short adding the dummy cat and removing it later. 

</pre>";

?>

1 Answer
1

Maybe this can help

delete_option('taxonomy-slug_children');

just replace the ‘taxonomy-slug’ with ‘cat’ or other taxonomy you are using.
This line is supposed to used in the same action hook function, right after you create the term.

Leave a Reply

Your email address will not be published. Required fields are marked *