• When i create two categories at once with wp_insert_term everything is okay:

    $cat1 = wp_insert_term('Parent', 'category');
    $cat2 = wp_insert_term('Parent2', 'category');

    They both show in categories.php and on my site. When i make the second category a child of the first however:

    $cat1 = wp_insert_term('Parent', 'category');
    $cat2 = wp_insert_term('Child', 'category', array('parent' => $cat1['term_id']));

    The child doesn’t show up, even though all the database entries are created properly (as fas as i can tell).

    The strange thing is that when i create another child-category in wp-admin, both children show up normally. Somehow the child i create in code isn’t ‘activated’, while regular parent categories don’t seem to need this.

    When the parent category already exists and i only create the child through code, everything works ok too. So the only scenario that doesn’t work is where i create a parent and then right afterwards the child.

    I’ve looked through the functions used to create taxonomies but i don’t see anything that i could use to force this.

    Any ideas?

Viewing 1 replies (of 1 total)
  • Use ID of tag_ID

    $test = wp_insert_term( "MY TERM2", "genre", $args = array('parent'=>'7') );
    echo "TEST="; var_dump($test);

Viewing 1 replies (of 1 total)
  • The topic ‘Can create two categories at once, but not if one is child of other?’ is closed to new replies.