get_object_taxonomies

The timeline below displays how wordpress function get_object_taxonomies has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Returns the names or objects of the taxonomies which are registered for the requested object or object type,
 * such as a post object or post type name.
 *
 * Example:
 *
 *     $taxonomies = get_object_taxonomies( 'post' );
 *
 * This results in:
 *
 *     Array( 'category', 'post_tag' )
 *
 * @since 2.3.0
 *
 * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
 *
 * @param string|string[]|WP_Post $object_type Name of the type of taxonomy object, or an object (row from posts).
 * @param string                  $output      Optional. The type of output to return in the array. Accepts either
 *                                             'names' or 'objects'. Default 'names'.
 * @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
 */
function get_object_taxonomies($object_type, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object_type)) {
        if ('attachment' === $object_type->post_type) {
            return get_attachment_taxonomies($object_type, $output);
        }
        $object_type = $object_type->post_type;
    }
    $object_type = (array) $object_type;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object_type, (array) $tax_obj->object_type)) {
            if ('names' === $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 6.1

/**
 * Returns the names or objects of the taxonomies which are registered for the requested object or object type,
 * such as a post object or post type name.
 *
 * Example:
 *
 *     $taxonomies = get_object_taxonomies( 'post' );
 *
 * This results in:
 *
 *     Array( 'category', 'post_tag' )
 *
 * @since 2.3.0
 *
 * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
 *
 * @param string|string[]|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string                  $output Optional. The type of output to return in the array. Accepts either
 *                                        'names' or 'objects'. Default 'names'.
 * @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ('attachment' === $object->post_type) {
            return get_attachment_taxonomies($object, $output);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' === $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 5.9

/**
 * Return the names or objects of the taxonomies which are registered for the requested object or object type, such as
 * a post object or post type name.
 *
 * Example:
 *
 *     $taxonomies = get_object_taxonomies( 'post' );
 *
 * This results in:
 *
 *     Array( 'category', 'post_tag' )
 *
 * @since 2.3.0
 *
 * @global WP_Taxonomy[] $wp_taxonomies The registered taxonomies.
 *
 * @param string|string[]|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string                  $output Optional. The type of output to return in the array. Accepts either
 *                                        'names' or 'objects'. Default 'names'.
 * @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ('attachment' === $object->post_type) {
            return get_attachment_taxonomies($object, $output);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' === $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 5.4

/**
 * Return the names or objects of the taxonomies which are registered for the requested object or object type, such as
 * a post object or post type name.
 *
 * Example:
 *
 *     $taxonomies = get_object_taxonomies( 'post' );
 *
 * This results in:
 *
 *     Array( 'category', 'post_tag' )
 *
 * @since 2.3.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param string|string[]|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string                  $output Optional. The type of output to return in the array. Accepts either
 *                                        'names' or 'objects'. Default 'names'.
 * @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ('attachment' === $object->post_type) {
            return get_attachment_taxonomies($object, $output);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' === $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 5.3

/**
 * Return the names or objects of the taxonomies which are registered for the requested object or object type, such as
 * a post object or post type name.
 *
 * Example:
 *
 *     $taxonomies = get_object_taxonomies( 'post' );
 *
 * This results in:
 *
 *     Array( 'category', 'post_tag' )
 *
 * @since 2.3.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param string|string[]|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string                  $output Optional. The type of output to return in the array. Accepts either
 *                                        'names' or 'objects'. Default 'names'.
 * @return string[]|WP_Taxonomy[] The names or objects of all taxonomies of `$object_type`.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ($object->post_type === 'attachment') {
            return get_attachment_taxonomies($object, $output);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' === $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 4.7

/**
 * Return the names or objects of the taxonomies which are registered for the requested object or object type, such as
 * a post object or post type name.
 *
 * Example:
 *
 *     $taxonomies = get_object_taxonomies( 'post' );
 *
 * This results in:
 *
 *     Array( 'category', 'post_tag' )
 *
 * @since 2.3.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param array|string|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string               $output Optional. The type of output to return in the array. Accepts either
 *                                     taxonomy 'names' or 'objects'. Default 'names'.
 * @return array The names of all taxonomy of $object_type.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ($object->post_type == 'attachment') {
            return get_attachment_taxonomies($object, $output);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' == $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 4.5

/**
 * Return the names or objects of the taxonomies which are registered for the requested object or object type, such as
 * a post object or post type name.
 *
 * Example:
 *
 *     $taxonomies = get_object_taxonomies( 'post' );
 *
 * This results in:
 *
 *     Array( 'category', 'post_tag' )
 *
 * @since 2.3.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param array|string|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string               $output Optional. The type of output to return in the array. Accepts either
 *                                     taxonomy 'names' or 'objects'. Default 'names'.
 * @return array The names of all taxonomy of $object_type.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ($object->post_type == 'attachment') {
            return get_attachment_taxonomies($object);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' == $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 4.3

/**
 * Return all of the taxonomy names that are of $object_type.
 *
 * It appears that this function can be used to find all of the names inside of
 * $wp_taxonomies global variable.
 *
 * `<?php $taxonomies = get_object_taxonomies('post'); ?>` Should
 * result in `Array( 'category', 'post_tag' )`
 *
 * @since 2.3.0
 *
 * @global array $wp_taxonomies The registered taxonomies.
 *
 * @param array|string|WP_Post $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string               $output Optional. The type of output to return in the array. Accepts either
 *                                     taxonomy 'names' or 'objects'. Default 'names'.
 * @return array The names of all taxonomy of $object_type.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ($object->post_type == 'attachment') {
            return get_attachment_taxonomies($object);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' == $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 4.1

/**
 * Return all of the taxonomy names that are of $object_type.
 *
 * It appears that this function can be used to find all of the names inside of
 * $wp_taxonomies global variable.
 *
 * `<?php $taxonomies = get_object_taxonomies('post'); ?>` Should
 * result in `Array( 'category', 'post_tag' )`
 *
 * @since 2.3.0
 *
 * @uses $wp_taxonomies
 *
 * @param array|string|object $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
 * @return array The names of all taxonomy of $object_type.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ($object->post_type == 'attachment') {
            return get_attachment_taxonomies($object);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' == $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 3.9

/**
 * Return all of the taxonomy names that are of $object_type.
 *
 * It appears that this function can be used to find all of the names inside of
 * $wp_taxonomies global variable.
 *
 * <code><?php $taxonomies = get_object_taxonomies('post'); ?></code> Should
 * result in <code>Array('category', 'post_tag')</code>
 *
 * @since 2.3.0
 *
 * @uses $wp_taxonomies
 *
 * @param array|string|object $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
 * @return array The names of all taxonomy of $object_type.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ($object->post_type == 'attachment') {
            return get_attachment_taxonomies($object);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' == $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}

WordPress Version: 3.7

/**
 * Return all of the taxonomy names that are of $object_type.
 *
 * It appears that this function can be used to find all of the names inside of
 * $wp_taxonomies global variable.
 *
 * <code><?php $taxonomies = get_object_taxonomies('post'); ?></code> Should
 * result in <code>Array('category', 'post_tag')</code>
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 *
 * @uses $wp_taxonomies
 *
 * @param array|string|object $object Name of the type of taxonomy object, or an object (row from posts)
 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
 * @return array The names of all taxonomy of $object_type.
 */
function get_object_taxonomies($object, $output = 'names')
{
    global $wp_taxonomies;
    if (is_object($object)) {
        if ($object->post_type == 'attachment') {
            return get_attachment_taxonomies($object);
        }
        $object = $object->post_type;
    }
    $object = (array) $object;
    $taxonomies = array();
    foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) {
        if (array_intersect($object, (array) $tax_obj->object_type)) {
            if ('names' == $output) {
                $taxonomies[] = $tax_name;
            } else {
                $taxonomies[$tax_name] = $tax_obj;
            }
        }
    }
    return $taxonomies;
}