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(...)):
else:
//error here?
endif;
See Codex page for
is_taxonomy
wp_insert_term
usestaxonomy_exists
to check if the taxonomy exists. This means if the taxonomy is a registered taxonomy. (It would be odd ifwp_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.