Paramètres

$object(string|string[]|WP_Post)requis

Objet de poste ou nom du type de poste.

$output(string)optionnel

Type de la sortie de la fonction retourné dans un tableau.

Valeur par défaut : 'names'

Retourne

(string[]|WP_Taxonomy[]) Les noms ou les objets de toutes les taxonomies attachées à $object.

Déclaration et structure de la fonction get_object_taxonomies()

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;
}
get_attachment_taxonomies()

Retourne les taxonomies attachées à un attachement donné.

Où est utilisée la fonction get_object_taxonomies() dans le CMS WordPress

Exemples

$taxonomies = get_object_taxonomies( 'post' );

// $taxonomies contient :
array( 'category', 'post_tag' );
$taxonomy_objects = get_object_taxonomies( 'post', 'objects' );
print_r( $taxonomy_objects);

// Affiche :
Array(
    [category] => stdClass Object
        (
            [hierarchical] => 1
            [update_count_callback] => 
            [rewrite] => 
            [query_var] => category_name
            [public] => 1
            [show_ui] => 1
            [show_tagcloud] => 1
            [_builtin] => 1
            [labels] => stdClass Object
                (
                    ...
                )
            ...
            [name] => category
            [label] => Categories
        )
    [post_tag] => stdClass Object
        (
            ...
        )
    [post_format] => stdClass Object
        (
            ....
        )
)

Sources

Codex WordPress : get_object_taxonomies()

Autres fonctions dans le même fichier : wp-includes/taxonomy.php

Retour