WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Now that is_taxonomy($taxonomy) function deprecated how do I know if a taxonomy exist? What's the alternative?

On a second note, the codex for wp_insert_term() says that if the taxonomy does not exist, an error is fired. Here, the "if taxonomy exists" part is ambiguous to me. Does that mean if the taxonomy has currently been registered with the registered_taxonomy or does that mean there is at least one term in the wp_term_taxonomy() table that's been associated with that taxonomy?

And my 3rd question final question is how do I catch an error when an error is raised by the wp_insert_term() function?

Would this work?

if (list($term_id,$taxonomy_id) = wp_insert_term(...)):
  //error here?
share|improve this question
up vote 1 down vote accepted

See Codex page for is_taxonomy

This function is deprecated as of Version 3.0. Please use taxonomy_exists instead.

wp_insert_term uses taxonomy_exists to check if the taxonomy exists. This means if the taxonomy is a registered taxonomy. (It would be odd if wp_insert_term only you allowed to add a term to taxonomies with existing terms :) )

To catch an error you can use is_wp_error. E.g.

$result = wp_insert_term(...);
if ( is_wp_error( $result ) ) {
   $error_string = $result->get_error_message();
   echo '<div id="message" class="error"><p>' . $error_string . '</p> </div>';
   list($term_id,$taxonomy_id) = $result;
share|improve this answer
Cool & thanks Stephen. What do you mean by "It would be odd if wp_insert_term only you allowed to add a term to taxonomies with existing terms". – Average Joe Apr 11 '12 at 0:05
Also, can you address the error checking part of my question too? – Average Joe Apr 11 '12 at 0:06
Done :). What I meant was that wp_insert_term is used to create taxonomy terms and it should be able to do that even if a taxonomy doesn't currently have any terms. – Stephen Harris Apr 11 '12 at 0:16
Let's continue on this here > wordpress.stackexchange.com/questions/48572/… – Average Joe Apr 11 '12 at 0:24

Your Answer


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.