WordPress获取分类法所有子级函数:get_term_children

WordPress函数get_term_children用于获取指定分类法的所有子级,例如:获取某个分类的所有子分类,该函数返回所有分类法子级的ID。

get_term_children( int $term_id, string $taxonomy )

函数参数

$term_id

整数

如果分类法为category,则传递分类的ID

$taxonomy

字符串

分类法的名称

函数返回值

以数组的形式返回所有子级的ID

函数使用示例

$childrens = get_term_children(6, 'category');
foreach($childrens as $cat) {
	echo '<li><a href="' . get_category_link($cat) . '">' . get_cat_name($cat) . '</a></li>';
}

扩展阅读

get_term_children()函数位于:wp-includes/taxonomy.php

相关函数:

阿里云