wp_get_object_terms

Sponsored Link

提供しているタクソノミーに、指定されたオブジェクトに関連しているタームを取得します。

Sponsored Link

Retrieves the terms associated with the given object(s), in the supplied taxonomies.

wp_get_object_termsのファンクションタグ使用方法

<?php wp_get_object_terms( $object_ids, $taxonomies, $args ) ?>

wp_get_object_termsのパラメーター

$object_ids

(string|array) (required)タームから取得するためのオブジェクトのIDです。
デフォルト:なし

(string|array) (required) The id’s of objects to retrieve terms from.
Default: None

$taxonomies

(string|array) (required)タームから取得するためのタクソノミーです。例: ‘category’, ‘post_tag’, ‘taxonomy slug’
デフォルト:なし

(string|array) (required) The taxonomies to retrieve terms from. For example: ‘category’, ‘post_tag’, ‘taxonomy slug’
Default: None

$args

(array|string) (optional)返される内容を変更する
デフォルト:配列

(array|string) (optional) Change what is returned
Default: array

デフォルトの引数

$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
Argument Options

以下の情報は、$argsパラメーターを行う必要があり、それが存在している場合、文字列或いはそのパラメーターの文字列に格納されることができます。

最初の引数は’orderby’と呼ばれ、’name’のデフォルト値を持っています。その他のサポートされている値は、’count’, ‘slug’, ‘term_group’, ‘term_order’, and ‘term_id’を含んでいます。

2番めの引数は’order’と呼ばれ、’ASC’のデフォルト値を持っています。受け入れ可能になっている他の値のみ’DESC’です。

最後のサポートされている引数は、’all’のデフォルト値を持っています。代わりに使用できる他の複数のオプションがあります。サポートされている値は次のとおりです:’all’, ‘ids’, ‘names’, ‘slugs’, で、最後はfinally ‘all_with_object_id’です。

フィールド引数も返ってくるのかを決定します。’all’あるいは’all_with_object_id’が選択されるかデフォルトをそのまま維持されている場合は、全ての一致するタームオブジェクトが返されます。’ids’, ‘slugs’ あるいは ‘names’が使用されている場合は、全ての一致するタームIDあるいはターム名の配列はそれぞれ返されます。

The following information has to do the $args parameter and for what can be contained in the string or array of that parameter, if it exists.

The first argument is called ‘orderby’ and has the default value of ‘name’. Other supported values include ‘count’, ‘slug’, ‘term_group’, ‘term_order’, and ‘term_id’.

The second argument is called ‘order’ and has the default value of ‘ASC’. The only other value that will be acceptable is ‘DESC’.

The final argument supported is called ‘fields’ and has the default value of ‘all’. There are multiple other options that can be used instead. Supported values are as follows: ‘all’, ‘ids’, ‘names’, ‘slugs’, and finally ‘all_with_object_id’.

The fields argument also decides what will be returned. If ‘all’ or ‘all_with_object_id’ is choosen or the default kept intact, then all matching terms objects will be returned. If ‘ids’, ‘slugs’ or ‘names’ is used, then an array of all matching term ids or term names will be returned respectively.

戻り値

(array|WP_Error)

要求されたタームデータあるいは空の配列は、タームが見つからない場合です。WP_Errorは$taxonomyが存在しない場合です。詳細については、is_wp_error()を参照してください。

The requested term data or empty array if no terms found. WP_Error if $taxonomy does not exist. See is_wp_error() for more information.

$postに適用されている全ての’product’タクソノミーのタームのリストを返します。

Return a list of all ‘product’ taxonomy terms which are applied to $post:

$product_terms = wp_get_object_terms($post->ID, 'product');
if(!empty($product_terms)){
  if(!is_wp_error( $product_terms )){
    echo '<ul>';
    foreach($product_terms as $term){
      echo '<li><a href="'.get_term_link($term->slug, 'product').'">'.$term->name.'</a></li>'; 
    }
    echo '</ul>';
  }
}

注意

  • Uses global: (object) $wpdb
  • May return WP_Error object.

変更ログ

Since: 2.3.0

ソースファイル

wp_get_object_terms()は、wp-includes/taxonomy.php内に位置しています。

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

関連ファンクションタグ

Terms: 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(), wp_get_object_terms(), wp_set_object_terms(), wp_get_post_terms(), wp_set_post_terms()

Sponsored Link