WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get object taxonomies

Description

Returns all the taxonomies for a post type or post object

Usage

<?php get_object_taxonomies$object$output ); ?>

Parameters

$object
(array|string|object) (required) Name of the post type, or a post object (row from posts)
Default: None
$output
(string) (optional) The type of output to return, either taxonomy 'names' or 'objects'.
Default: 'names'

Return Values

(array) 
All taxonomy names or objects for the given post type/post object

Examples

Taxonomy objects for post type

If the $output parameter is 'objects', taxonomy objects will be returned as described in get_taxonomies()

<?php 

   $taxonomy_objects = get_object_taxonomies( 'post', 'objects' );
   print_r( $taxonomy_objects);

?>

will output

Array
(
    [category] => stdClass Object
        (
            [hierarchical] => 1
            [update_count_callback] => 
            [rewrite] => 
            [query_var] => category_name
            [public] => 1
            [show_ui] => 1
            [show_tagcloud] => 1
            [_builtin] => 1
            [labels] => stdClass Object
                (
                    ...
                )

            ...

            [name] => category
            [label] => Categories
        )

    [post_tag] => stdClass Object
        (
            ...
        )

    [post_format] => stdClass Object
        (
            ....
        )

)

Taxonomy names for post object

To get the taxonomies for the current post, the current post object can be passed instead of the post type

<?php 

    function get_current_post_taxonomies(){
        global $post;

        $taxonomy_names = get_object_taxonomies( $post );
        print_r( $taxonomy_names );
    }

    add_action('wp_head','get_current_post_taxonomies');

?>

will output


Array
(
    [0] => category
    [1] => post_tag
    [2] => post_format
)

Change Log

Since: 2.3.0

Source File

get_object_taxonomies() is located in wp-includes/taxonomy.php.

Related

See also index of Function Reference and index of Template Tags.