get_terms

Sponsored Link

タクソノミーのタームやタクソノミーのリストを取得します。

Sponsored Link

Retrieve the terms in taxonomy or list of taxonomies.

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

<?php get_terms( $taxonomies, $args ) ?>

デフォルトの使用方法

<?php 
// デフォルト値はありません。例としてこれらを使用しています。
$taxonomies = array( 
    'post_tag',
    'my_tax',
);

$args = array(
    'orderby'       => 'name', 
    'order'         => 'ASC',
    'hide_empty'    => true, 
    'exclude'       => array(), 
    'exclude_tree'  => array(), 
    'include'       => array(),
    'number'        => , 
    'fields'        => 'all', 
    'slug'          => , 
    'parent'         => ,
    'hierarchical'  => true, 
    'child_of'      => 0, 
    'get'           => , 
    'name__like'    => ,
    'pad_counts'    => false, 
    'offset'        => , 
    'search'        => , 
    'cache_domain'  => 'core'
); 
?> 

get_termsのパラメーター

$taxonomies

(string|array) (required)タームから取得するためのタクソノミー
デフォルト:なし

(string|array) (required) The taxonomies to retrieve terms from.
Default: None

$args

(string|array) (optional) 返されるものを変更してください。
デフォルト:配列

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

可能な引数

orderby

(string)

  • id
  • count
  • name – Default
  • slug
  • term_group
  • none

order

(string)

  • ASC – Default
  • DESC

hide_empty

(boolean)空の$termsを返すかどうか

(boolean) Whether to return empty $terms.

  • 1 (true) – Default (i.e. Do not show empty terms)
  • 0 (false)

exclude

(integer)除外するタームIDの配列

(integer) An array of term ids to exclude

exclude_tree

除外する親のタームIDの配列

(integer) An array of parent term ids to exclude

include

(integer)インクルードするタームIDの配列。空の場合は全てを返します。

(integer) An array of term ids to include. Empty returns all.

number

(integer)返すためのタームの最大数。デフォルトは全てのタームを返します。

(integer) The maximum number of terms to return. Default is to return them all.

fields

(string)

  • all – タームオブジェクトの配列を返します – デフォルト
  • ids – 整数の配列を返します。
  • names – 文字列の配列を返します。
  • count – (3.2+) 見つかったターム数を返します
  • id=>parent – キーがタームIDで、値が存在するか0の場合、親タームIDである連想配列を返します。
  • all – returns an array of term objects – Default
  • ids – returns an array of integers
  • names – returns an array of strings
  • count – (3.2+) returns the number of terms found
  • id=>parent – returns an associative array where the key is the term id and the value is the parent term id if present or 0

slug

(string)”slug”がこの値に一致するタームを返します。デフォルトは空の文字列です。

(string) Returns terms whose “slug” matches this value. Default is empty string.

parent

(integer)このタームの直接の子を取得します(明示的な親がこの値であるタームのみ)0が渡された場合は、トップレベルのタームのみが返されます。デフォルトは空白の文字列です。

(integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.

hierarchical

(boolean) 空でない子孫を持つタームを含めるかどうか(’hide_empty’がtrueに設定されている場合でも)。

(boolean) Whether to include terms that have non-empty descendants (even if ‘hide_empty’ is set to true).

  • 1 (true) – Default
  • 0 (false)

child_of

(integer)このタームの全ての子孫を取得します。デフォルトは0です。

(integer) Get all descendents of this term. Default is 0.

get

(string)デフォルトは何もありません。’hide_empty’と’child_of’の上書きを許可し、’all’に値を設定することによって行うことができます。

(string) Default is nothing . Allow for overwriting ‘hide_empty’ and ‘child_of’, which can be done by setting the value to ‘all’.

name__like

(string)デフォルトは空の文字列です。

(string) Default is empty string.

pad_counts

trueの場合、$termsと同様に子の全てをカウントします。

(boolean) If true, count all of the children along with the $terms.

  • 1 (true)
  • 0 (false) – Default

offset

(integer)タームクエリを相殺するための番号。

(integer) The number by which to offset the terms query.

search

(string)ターム名が一致する事を望んでいます。LIKE %term name%クエリーを行います。

(string) The term name you wish to match. It does a LIKE %term name% query.

cache_domain

(string)バージョン3.2以降。’cache_domain’引数は、get_terms()によって生成されたクエリーがオブジェクトキャッシュに格納されている時に生成されるユニークのキャッシュキーが有効になります。例えば、あなたがクエリーを変更するためにこの関数のフィルターの1つを使用する場合(’terms_clauses’のように)、ユニークな値のために’cache_domain’を設定することは、似たようなクエリーにキャッシュを上書きしません。デフォルト値は’core’です。
注:引数はwp_parse_args()で使用される形式で渡されます。例えば。

(string) Version 3.2 and above. The ‘cache_domain’ argument enables a unique cache key to be produced when the query produced by get_terms() is stored in object cache. For instance, if you are using one of this function’s filters to modify the query (such as ‘terms_clauses’), setting ‘cache_domain’ to a unique value will not overwrite the cache for similar queries. Default value is ‘core’.
NOTE: Arguments are passed in the format used by wp_parse_args(). e.g.

戻り値

(mixed) データベースからタームROWです。$taxonomyが存在しないか$termが見つからない場合はfalseを返します。
フィールドは次のとおりです:

(mixed)
Term Row from database. Will return false if $taxonomy does not exist or $term was not found.
The fields returned are:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • count

カウントで並べられた全ての投稿のカテゴリーを取得します。

Get all post categories ordered by count.

文字列のシンタックス:

String syntax:

$categories = get_terms( 'category', 'orderby=count&amp;hide_empty=0' );
Array syntax:

 $categories = get_terms( 'category', array(
 	'orderby'    => 'count',
 	'hide_empty' => 0
 ) );

すべてのリンクのカテゴリーを取得します。

Get all the links categories:

$mylinks_categories = get_terms('link_category', 'orderby=count&amp;hide_empty=0');

リンクせずに、カスタムタクソノミー内の全てのタームを一覧表示します。

List all the terms in a custom taxonomy, without a link:

$terms = get_terms(“my_taxonomy”);
$count = count($terms);
if ( $count > 0 ){
echo “

    “;
    foreach ( $terms as $term ) {
    echo “

  • ” . $term->name . “
  • “;

    }
    echo “

“;
}

句読点 (·)で区切られた、タームアーカイブへのリンクに、全てのタームを一覧表示します。(言語固有の、WPMLメソッド):

List all the terms, with link to term archive, separated by an interpunct (·). (language specific, WPML method):

$args = array( 'taxonomy' => 'my_term' );

$terms = get_terms('my_term', $args);

$count = count($terms); $i=0;
if ($count > 0) {
    $cape_list = '<p class="my_term-archive">';
    foreach ($terms as $term) {
        $i++;
    	$term_list .= '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
    	if ($count != $i) $term_list .= ' &amp;middot; '; else $term_list .= '</p>';
    }
    echo $term_list;
}

詳細

あなたはそれが送信される前にクエリーに任意のカスタマイズを注入したり、フィルターを使用して出力を制御することができます。

キャッシュがタームを持ち、$argsの配列と$taxonomiesの配列と共に発見するタームを渡す時に、’get_terms’フィルターは呼び出されます。

タームの配列が渡され、$taxonomiesと$argsと同様に、タームの配列を渡すことになる前に、このフィルターも呼ばれます。

‘list_terms_exclusions’フィルターは、$argsと同様にコンパイルされた除外を渡します。

You can inject any customizations to the query before it is sent or control the output with filters.

The ‘get_terms’ filter will be called when the cache has the term and will pass the found term along with the array of $taxonomies and array of $args.

This filter is also called before the array of terms is passed and will pass the array of terms, along with the $taxonomies and $args.

The ‘list_terms_exclusions’ filter passes the compiled exclusions along with the $args.

ソースファイル

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

get_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