Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted
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.

share|improve this answer
    
that's exactly what I was looking for, thanks ) –  CBeTJlu4ok May 14 '13 at 3:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.