get_term_children

Sponsored Link

シングルの配列に全てのタームの子をマージします。

Sponsored Link

この再帰関数は、同じ配列に$termの子の全てをマージします。階層構造になっているタクソノミーに対してのみ有用です。

$termが $taxonomyに存在しない場合、空の配列を返します。

Merge all term children into a single array.

This recursive function will merge all of the children of $term into the same array. Only useful for taxonomies which are hierarchical.

Will return an empty array if $term does not exist in $taxonomy.

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

<?php get_term_children( $term, $taxonomy ) ?>

get_term_childrenのパラメーター

$term

(string) (required) 子を取得するためのタームのID
デフォルト:なし

(string) (required) ID of Term to get children
Default: None

$taxonomy

(string) (required)タクソノミー名
デフォルト:なし

(string) (required) Taxonomy Name
Default: None

戻り値

(array|WP_Error)

タームIDの配列。WP_Errorは$taxonomyが存在しない場合に返します。

Array of Term IDs. WP_Error returned if $taxonomy does not exist

基本的な例

子のタクソノミーの配列を取得し、順不同リスト内のリンクでそれらを書き出すために使用します。

Used to get an array of children taxonomies and write them out with links in an unordered list.

<?php
$termID = 10;
$taxonomyName = "products";
$termchildren = get_term_children( $termID, $taxonomyName );

echo '<ul>';
foreach ($termchildren as $child) {
	$term = get_term_by( 'id', $child, $taxonomyName );
	echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?> 

これは同じようなものを返しています。

This would return something like.

<ul> 
<li><a href="link_to_term_page">Term 1</a></li>
<li><a href="link_to_term_page">Term 2</a></li>
</ul>

注意

  • 用途: $wpdb
  • 用途: _get_term_hierarchy()
  • 用途: get_term_childrenは、$taxonomyと親$termの両方の子を取得するために使用します。
  • Uses: $wpdb
  • Uses: _get_term_hierarchy()
  • Uses: get_term_children Used to get the children of both $taxonomy and the parent $term

変更ログ

Since: 2.3.0

ソースファイル

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

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