Support » Fixing WordPress » wp_insert_term trouble creating parent/child relationships

  • 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…

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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

    Score, thanks Matt!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_insert_term trouble creating parent/child relationships’ is closed to new replies.