The get_taxonomy() WordPress PHP function retrieves the taxonomy object of a given taxonomy.
Usage
get_taxonomy( $taxonomy );
Example:
Input:
$my_taxonomy = get_taxonomy( 'category' );
print_r( $my_taxonomy );
Output:
stdClass Object ( [hierarchical] => 1 [update_count_callback] => _update_post_term_count [rewrite] => Array ( [slug] => category [with_front] => 1 ) [query_var] => category [public] => 1 ... )
Parameters
- $taxonomy (string) – Required. Name of the taxonomy object to return.
More information
See WordPress Developer Resources: get_taxonomy
Examples
Display Taxonomy Labels
Display the labels of a custom taxonomy called ‘genre’:
$genre_taxonomy = get_taxonomy( 'genre' ); echo 'Taxonomy labels: '; echo implode(', ', (array) $genre_taxonomy->labels);
Check if Taxonomy is Hierarchical
Determine if a taxonomy called ‘location’ is hierarchical:
$location_taxonomy = get_taxonomy( 'location' ); if ( $location_taxonomy->hierarchical ) { echo 'The location taxonomy is hierarchical.'; } else { echo 'The location taxonomy is not hierarchical.'; }
Get Taxonomy Rewrite Rules
Retrieve the rewrite rules for a taxonomy called ‘platform’:
$platform_taxonomy = get_taxonomy( 'platform' ); echo 'Rewrite rules: '; print_r( $platform_taxonomy->rewrite );
Get Taxonomy Capabilities
Display the capabilities associated with a custom taxonomy called ‘skill’:
$skill_taxonomy = get_taxonomy( 'skill' ); echo 'Capabilities: '; print_r( $skill_taxonomy->cap );
Check if Taxonomy is Public
Determine if a taxonomy called ‘department’ is public:
$department_taxonomy = get_taxonomy( 'department' ); if ( $department_taxonomy->public ) { echo 'The department taxonomy is public.'; } else { echo 'The department taxonomy is not public.'; }