• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

関数リファレンス/get object taxonomies

提供: WordPress Codex 日本語版
< 関数リファレンス
2014年7月6日 (日) 01:17時点におけるGblsm (トーク | 投稿記録)による版 (en:Function Reference/get object taxonomies 09:38, 21 August 2013 Saurabhshukla 版)

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

Description

Returns all the taxonomies for a post type or post object

Usage

%%%<?php get_object_taxonomies( $object, $output ); ?>%%%

Parameters

$object
array|string|object) (必須) Name of the post type, or a post object (row from posts)
初期値: なし
$output
string) (optional) The type of output to return, either taxonomy 'names' or 'objects'.
初期値: 'names'

Return Values

(array) 
All taxonomy names or objects for the given post type/post object

Examples

Taxonomy names for post type

<?php 

   $taxonomy_names = get_object_taxonomies( 'post' );
   print_r( $taxonomy_names);

?>

will typically output:


Array
(
    [0] => category
    [1] => post_tag
    [2] => post_format
)

Taxonomy objects for post type

If the $output parameter is 'objects', taxonomy objects will be returned as described in get_taxonomies()

<?php 

   $taxonomy_objects = get_object_taxonomies( 'post', 'objects' );
   print_r( $taxonomy_objects);

?>

will output

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
        (
            ....
        )

)

Taxonomy names for post object

To get the taxonomies for the current post, the current post object can be passed instead of the post type

<?php 

    function get_current_post_taxonomies(){
        global $post;

        $taxonomy_names = get_object_taxonomies( $post );
        print_r( $taxonomy_names );
    }

    add_action('wp_head','get_current_post_taxonomies');

?>

will output


Array
(
    [0] => category
    [1] => post_tag
    [2] => post_format
)

Change Log

Since: 2.3.0

Source File

get_object_taxonomies() is located in wp-includes/taxonomy.php.

Related

タームタグ: is_term(), term_exists(), get_objects_in_term(), get_term(), get_term_by(), get_term_children(), get_term_link(), get_terms(), get_the_terms(), get_the_term_list(), has_term(), sanitize_term(), the_terms(), get_object_taxonomies() is_object_in_taxonomy() the_taxonomies() wp_get_object_terms(), wp_set_object_terms(), wp_get_post_terms(), wp_set_post_terms(), wp_delete_object_term_relationships()


関数リファレンステンプレートタグ目次もご覧ください。