taxonomy_exists()WP 3.0.0

Checks if the specified taxonomy exists.

This is a so-called conditional tag, a logical function that returns "true" or "false", depending on whether the condition is met or not.

This is a replacement for the deprecated function is_taxonomy()

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.

Returns

true|false.

Usage

<?php taxonomy_exists($taxonomy); ?>
$taxonomy(string) (required)
The name of the taxonomy whose existence needs to be checked, for example: "category".

Examples

4

#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() code WP 6.9

function taxonomy_exists( $taxonomy ) {
	global $wp_taxonomies;

	return is_string( $taxonomy ) && isset( $wp_taxonomies[ $taxonomy ] );
}