wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_object_taxonomies › WordPress Function

Seit2.3.0
Veraltetn/v
get_object_taxonomies ( $object_type, $output = 'names' )
Parameter: (2)
  • (string|string[]|WP_Post) $object_type Name of the type of taxonomy object, or an object (row from posts).
    Erforderlich: Ja
  • (string) $output Optional. The type of output to return in the array. Accepts either 'names' or 'objects'. Default 'names'.
    Erforderlich: Nein
    Standard: 'names'
Gibt zurück:
  • (string[]|WP_Taxonomy[]) The names or objects of all taxonomies of `$object_type`.
Definiert in:
Codex:

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


Quellcode

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