get_term

Sponsored Link

タームIDによってデータベースから全てのタームデータを取得します。名前、スラッグ、IDでタームデータを取得するには、代わりにget_term_by() を使用してください。

Sponsored Link

get_term関数の使用方法は、タームオブジェクトにフィルターを適用することです。フィルターを適用する前にデータベースからタームオブジェクトを取得することが可能です。

$term IDは、データベースから取得するために、$taxonomyの一部でなければなりません。不具合はフックで攻略することが出来るかもしれません。不具合は get_rowメソッドを返す$wpdbとして同じ値になるでしょう。

2つのフックがあり、1つは’get_term’と名付けられた各タームに、2つ目は’term_$taxonomy’というタクソノミー名に特化しています。両方のフックはタームオブジェクトと、パラメータとしてタクソノミー名を取得します。両方のフックはタームオブジェクトを返すはずです。

‘get_term’フックータームオブジェクトとタームタクソノミーである2つのパラメーターを取得します。タームオブジェクトを返す必要があります。全ての $termにキャッチオールフィルターとして、get_term()に使用します。

‘get_$taxonomy’フックータームオブジェクトとタームタクソノミーである2つのパラメーターを取得します。タームオブジェクトを返す必要があります。$taxonomyはタクソノミー名になり、例えば、’category’の場合は、フィルター名として’get_category’になります。カスタムタクソノミーやデフォルトのタクソノミーに差し込むのに便利です。

Get all Term data from database by Term ID. To retrieve term data by name, slug or ID, use get_term_by() instead

The usage of the get_term function is to apply filters to a term object. It is possible to get a term object from the database before applying the filters.

$term ID must be part of $taxonomy, to get from the database. Failure, might be able to be captured by the hooks. Failure would be the same value as $wpdb returns for the get_row method.

There are two hooks, one is specifically for each term, named ‘get_term’, and the second is for the taxonomy name, ‘term_$taxonomy’. Both hooks gets the term object, and the taxonomy name as parameters. Both hooks are expected to return a Term object.

‘get_term’ hook – Takes two parameters the term Object and the taxonomy name. Must return term object. Used in get_term() as a catch-all filter for every $term.

‘get_$taxonomy’ hook – Takes two parameters the term Object and the taxonomy name. Must return term object. $taxonomy will be the taxonomy name, so for example, if ‘category’, it would be ‘get_category’ as the filter name. Useful for custom taxonomies or plugging into default taxonomies.

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

<?php get_term( $term, $taxonomy, $output, $filter ) ?>

get_termのパラメーター

$term

(integer|object) (required)整数の場合は、データベースから取得します。objectの場合はフィルターを適用して$termを返します。
デフォルト:なし

(integer|object) (required) If integer, will get from database. If object will apply filters and return $term.
Default: None

$taxonomy

(string) (required)$termがその一部となっているタクソノミー名。
デフォルト:なし

(string) (required) Taxonomy name that $term is part of.
Default: None

$output

(string) (optional)定数であるOBJECT, ARRAY_A, ARRAY_N
デフォルト:OBJECT

(string) (optional) Constant OBJECT, ARRAY_A, or ARRAY_N
Default: OBJECT

$filter

(string) (optional) デフォルトはrawあるいは全くWordPressが定義したフィルタは適用されません。
デフォルト:’raw’

(string) (optional) default is raw or no WordPress defined filter will applied.
Default: ‘raw’

戻り値

(mixed|null|WP_Error)
データベースからタームRow。$termが空の場合はnullを返します。タクソノミーが存在しない場合は、WP_Errorが返されます。

(mixed|null|WP_Error)
Term Row from database. Will return null if $term is empty. If taxonomy does not exist then WP_Error will be returned.

Get Term offers some handy information, but unfortunately lacks a link value.

$term = get_term( $term_id, $taxonomy );

Gives you term slug: e.g.: term-slug-example

$slug = $term->slug;

Gives you term name: e.g. Term Name Example

$name = $term->name;

Gives you term description: e.g. This is my new cool custom term.

$desc = $term->description;

注意

  • See sanitize_term_field() The $context param lists the available values for get_term_by() $filter param.
  • Uses: sanitize_term() Cleanses the term based on $filter context before returning.
  • Uses global: (object) $wpdb

変更ログ

Since: 2.3.0

ソースファイル

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

get_term() 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(), get_objects_in_term()

Sponsored Link