get_taxonomy( string $taxonomy )

Retrieves the taxonomy object of $taxonomy.


Description Description

The get_taxonomy function will first check that the parameter string given is a taxonomy object and if it is, it will return it.


Parameters Parameters

$taxonomy

(string) (Required) Name of taxonomy object to return.


Top ↑

Return Return

(WP_Taxonomy|false) The Taxonomy Object or false if $taxonomy doesn't exist.


Top ↑

Source Source

File: wp-includes/taxonomy.php

261
262
263
264
265
266
267
268
269
function get_taxonomy( $taxonomy ) {
    global $wp_taxonomies;
 
    if ( ! taxonomy_exists( $taxonomy ) ) {
        return false;
    }
 
    return $wp_taxonomies[ $taxonomy ];
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    For example for a custom taxonomy named “features” associated with a custom post type named “rentals”.

    1
    2
    $rental_features = get_taxonomy( 'features' );
    print_r( $rental_features );

    Result:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    stdClass Object (
        [hierarchical] =>
        [update_count_callback] =>
        [rewrite] =>
            Array ( [slug] => features [with_front] => 1 )
        [query_var] => features
        [public] => 1
        [show_ui] => 1
        [show_tagcloud] => 1
        [_builtin] =>
        [labels] =>
            stdClass Object (
                [name] => Features
                [singular_name] => Feature
                [search_items] => Search Features
                [popular_items] => Popular Features
                [all_items] => All Features
                [parent_item] => Parent Feature
                [parent_item_colon] => Parent Feature:
                [edit_item] => Edit Feature
                [update_item] => Update Feature
                [add_new_item] => Add New Feature
                [new_item_name] => New Feature Name
                [separate_items_with_commas] => Separate Features with commas
                [add_or_remove_items] => Add or remove Features
                [choose_from_most_used] => Choose from the most used Features
            )
        [show_in_nav_menus] => 1
        [label] => Features
        [singular_label] => Feature
        [cap] =>
            stdClass Object (
                [manage_terms] => manage_categories
                [edit_terms] => manage_categories
                [delete_terms] => manage_categories
                [assign_terms] => edit_posts
            )
        [name] => features
        [object_type] =>
            Array ( [0] => rentals [1] => rentals )
        )

You must log in before being able to contribute a note or feedback.