is_taxonomy is deprecated. What’s the alternative?

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?

Read More

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(...)):
else:
  //error here?
endif;

Related posts

Leave a Reply

1 comment

  1. 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>';
    }else{
       list($term_id,$taxonomy_id) = $result;
     }