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 '
  • ' . get_cat_name($cat) . '
  • '; }

    扩展阅读

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

    相关函数:

    原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/2248.html

    Like (0)
    Previous 2025年3月8日
    Next 2025年3月8日

    相关推荐

    发表回复

    您的邮箱地址不会被公开。 必填项已用 * 标注