WordPress at a glance

get_object_taxonomies() WP 1.0

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' )

Notes:

  • Global. Array. $wp_taxonomies The registered taxonomies.
✈ 1 time = 0.000055s = very fast | 50000 times = 0.90s = very fast

No Hooks.

Return

Array. The names of all taxonomy of $object_type.

Usage

get_object_taxonomies( $object, $output );
$object(array/string/WP_Post) (required)
Name of the type of taxonomy object, or an object (row from posts)
$output(string)
The type of output to return in the array. Accepts either taxonomy 'names' or 'objects'.
Default: 'names'

Code of get_object_taxonomies: wp-includes/taxonomy.php VER 4.9.8

<?php
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;
}

Related Functions

From category: For posts

No comments
    Hello, !     Log In . Register