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

(array) get_object_taxonomies( (array|string|WP_Post) $object, (string) $output = 'names' ); 

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

  1. if ( !function_exists( 'get_object_taxonomies' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // Name of the type of taxonomy object, or an object (row from posts) 
  5. $object = null; 
  6.  
  7. // Optional. The type of output to return in the array. Accepts either 
  8. // taxonomy 'names' or 'objects'. Default 'names'. 
  9. $output = 'names'; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = get_object_taxonomies($object, $output); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/taxonomy.php  
  1. function get_object_taxonomies( $object, $output = 'names' ) { 
  2. global $wp_taxonomies; 
  3.  
  4. if ( is_object($object) ) { 
  5. if ( $object->post_type == 'attachment' ) 
  6. return get_attachment_taxonomies($object); 
  7. $object = $object->post_type; 
  8.  
  9. $object = (array) $object; 
  10.  
  11. $taxonomies = array(); 
  12. foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) { 
  13. if ( array_intersect($object, (array) $tax_obj->object_type) ) { 
  14. if ( 'names' == $output ) 
  15. $taxonomies[] = $tax_name; 
  16. else 
  17. $taxonomies[ $tax_name ] = $tax_obj; 
  18.  
  19. return $taxonomies;