get_taxonomy()
Gets an object containing settings (data) of the specified taxonomy.
The function retrieves taxonomy data, not a list of terms of the specified taxonomy. To get the list of terms, use get_terms() or wp_list_categories().
The get_taxonomy function will first check that the parameter string given is a taxonomy object and if it is, it will return it.
1 time — 0.000009 sec (speed of light) | 50000 times — 0.01 sec (speed of light) | PHP 7.0.14, WP 4.7
No Hooks.
Return
WP_Taxonomy|false
. The taxonomy object or false if $taxonomy doesn't exist.
Usage
get_taxonomy( $taxonomy );
- $taxonomy(string) (required)
- Name of taxonomy object to return.
Examples
#1 Get taxonomy data
To demonstrate how this function works, let's get "category" taxonomy data, which is attached to the "post" post type:
$category_tax_features = get_taxonomy('category'); print_r( $category_tax_features );
Displays:
stdClass Object ( [labels] => stdClass Object ( [name] => Categories [singular_name] => Category [search_items] => Search Categories [popular_items] => [all_items] => All Categories [parent_item] => Parent Category [parent_item_colon] => Parent Category: [edit_item] => Edit Category [view_item] => View Category [update_item] => Update Category [add_new_item] => Add New Category [new_item_name] => New Category Name [separate_items_with_commas] => [add_or_remove_items] => [choose_from_most_used] => [not_found] => [menu_name] => Categories [name_admin_bar] => category ) [description] => [public] => 1 [hierarchical] => 1 [show_ui] => 1 [show_in_menu] => 1 [show_in_nav_menus] => 1 [show_tagcloud] => 1 [meta_box_cb] => post_categories_meta_box [rewrite] => Array ( [with_front] => [hierarchical] => 1 [ep_mask] => 512 [slug] => cat ) [query_var] => category_name [update_count_callback] => [_builtin] => 1 [show_admin_column] => 1 [cap] => stdClass Object ( [manage_terms] => manage_categories [edit_terms] => manage_categories [delete_terms] => manage_categories [assign_terms] => edit_posts ) [name] => category [object_type] => Array ( [0] => post ) [label] => Categories )
Notes
- Global. WP_Taxonomy[]. $wp_taxonomies The registered taxonomies.
Changelog
Since 2.3.0 | Introduced. |
get_taxonomy() get taxonomy code WP 6.6.2
function get_taxonomy( $taxonomy ) { global $wp_taxonomies; if ( ! taxonomy_exists( $taxonomy ) ) { return false; } return $wp_taxonomies[ $taxonomy ]; }