I’m using wp_insert_term to create categories, after the category is created I’d like to get its ID:

$cat_id = wp_insert_term($name, 'category', array('slug' => $slug) );

…however when I try to print $cat_id I get Array instead of the actual ID. I guess I have to state which part of the array I need, but I don’t really know what the variable for the ID would be?

2 Answers
2

It should be a key of term_id, so echo out $cat_id['term_id'] and you should get the new terms ID.

Tags:

Leave a Reply

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