taxonomy_exists()
Checks that the taxonomy name exists.
Formerly is_taxonomy(), introduced in 2.3.0.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Used By: is_taxonomy_hierarchical()
1 time — 0.00001 sec (speed of light) | 50000 times — 0.02 sec (speed of light) | PHP 7.0.14, WP 4.7
No Hooks.
Return
true|false
. Whether the taxonomy exists.
Usage
taxonomy_exists( $taxonomy );
- $taxonomy(string) (required)
- Name of taxonomy object.
Examples
#1 Various options for checks:
$taxonomy_exist = taxonomy_exists('category'); //returns true $taxonomy_exist = taxonomy_exists('post_tag'); //returns true $taxonomy_exist = taxonomy_exists('link_category'); //returns true $taxonomy_exist = taxonomy_exists('my_taxonomy'); //returns false if global variable $wp_taxonomies['my_taxonomy'] does not exist
Notes
- Global. WP_Taxonomy[]. $wp_taxonomies The registered taxonomies.
Changelog
Since 3.0.0 | Introduced. |
taxonomy_exists() taxonomy exists code WP 6.7.1
function taxonomy_exists( $taxonomy ) { global $wp_taxonomies; return is_string( $taxonomy ) && isset( $wp_taxonomies[ $taxonomy ] ); }