wp_insert_term trouble creating parent/child relationships (3 posts)

  1. crt
    Posted 3 years ago #

    Building a plugin... and I have an array that loops through wp_insert_term to create a bunch of terms for my taxonomy. Because they are in the correct order in the array, I can callback to get the parent id and use it to form a parent/child relationship.

    These relationships are formed, and can be found in the database, but using get_terms doesn't provide the children UNLESS I create 1 child the old fashioned way in the dashboard.

    What happens when I create a term in the dashboard editor that finishes the installation of my taxonomy plugin? And how can I fix it...

  2. Matt Thiessen
    Posted 2 years ago #

    Clear the children cache for your taxonomy after you insert a new child

    wp_insert_term( $new_name, $my_taxonomy, array( 'parent'=> (int)$new__term_id ) );
    delete_option($my_taxonomy."_children"); // clear the cache
  3. styledev
    Posted 2 years ago #

    Score, thanks Matt!

Topic Closed

This topic has been closed to new replies.

About this Topic