get_object_taxonomies

Definition:
function get_object_taxonomies($object, $output = 'names') {}

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.

Parameters

  • array|string|object $object: Name of the type of taxonomy object, or an object (row from posts)
  • string $output: The type of output to return, either taxonomy ‘names’ or ‘objects’. ‘names’ is the default.

Return values

returns:The names of all taxonomy of $object_type.

Source code

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;

}

1510

No comments yet... Be the first to leave a reply!

Leave a comment