2

I'm using wp_insert_term which works quite well

Now I want some error handler for when using the same name.

$term_id = wp_insert_term( $term, 'wpsc_product_category', $args );
if($term_id) {//my operations here}

where $term = $_POST['categoryTitle'];

I want to display some error when such name already exists.

In wp_insert_term, how to check if this $term_id is duplicate?
I don't want to continue my operations on already existing terms.

4
if ( is_wp_error($term_id) ) {

  // oops WP_Error obj returned, so the term existed prior
  // echo $term_id->get_error_message();
}

See if that works for you.

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.