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


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


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.


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. 


  • Similar question here: wordpress.stackexchange.com/questions/49576/…
    – offroff
    Apr 20, 2012 at 5:40
  • Why are you using wp_insert_term instead of wp_insert_category? You have the term name defined, but you're not adding the parameters of name, slug, or description. wp_insert_category does add those.
    – Otto
    Apr 20, 2012 at 10:38
  • Otto, wp insert category requires a login cause its defined in the admin folder. I'm doing this programmatic insertions from standalone php pages and when I tried using the wp insert cat on that php page I m getting stuck on the login screen cause it keeps constantly redirecting back. Apr 20, 2012 at 12:04
  • No, it doesn't. At least, not in a typical installation, that just happens to be where the containing php file is located. Internally, wp_insert_category() calls wp_insert_term() anyway ... Use the right tool for the job.
    – EAMann
    Apr 20, 2012 at 16:01
  • EAMan, So where would I run the php file then? Under which wp folder? wp-admin? Core files/folders get replaced with every update. Isn't it better to understand why this is happening and programmatically address it? I mean - don't you find the behaviour odd? Apr 20, 2012 at 21:45

1 Answer 1


Maybe this can help


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.

  • I had the same issue with child terms and above did the trick! Just make sure to use delete_option() after inserting the terms to be safe.
    – Rezen
    Aug 23, 2012 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.