get_object_taxonomies
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.
Description
Example:
This results in:
Returns (array)
The names of all taxonomy of $object_type.
Parameters (2)
- 0. $object (array|string|WP_Post)
- Name of the type of taxonomy object, or an object (row from posts)
- 1. $output — Optional. (string) =>
'names'
- The type of output to return in the array. Accepts either taxonomy names or objects.. Default names .
Usage
if ( !function_exists( 'get_object_taxonomies' ) ) { require_once ABSPATH . WPINC . '/taxonomy.php'; } // Name of the type of taxonomy object, or an object (row from posts) $object = null; // Optional. The type of output to return in the array. Accepts either // taxonomy 'names' or 'objects'. Default 'names'. $output = 'names'; // NOTICE! Understand what this does before running. $result = get_object_taxonomies($object, $output);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/taxonomy.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;
- }