Wordpress-只获取自定义分类法/类别的直接子级


Wordpress - Get custom taxonomy/category direct children only

我有下面的代码,它正在拉入所有子类别,包括grand children-我如何编辑它,使其只拉入直接子类别?

 $subCategories = get_term_children( $categoryID, 'product_club' );
$subcategoryData = '[';
if(!empty($subCategories)) {
$isFirst = true;
foreach($subCategories as $subCategory) {
  $term = get_term_by( 'id', $subCategory, 'product_club' );
  if(!$isFirst) $subcategoryData .= ', ';
  $isFirst = false;
  $subcategoryData .= '{"id": '.$term->term_id.', "name": "'.$term->name.'"}';
}
}
$subcategoryData .= ']';
echo $subcategoryData;
die;

非常感谢!!

可能需要进行一些调整。这将获得分类类型为"product_club"的$categoryID的所有直接子级。

$args = array(
    'child_of' => $categoryID,
    'taxonomy' => 'product_club',
    'hide_empty' => 0,
    'hierarchical' => true,
    'depth'  => 1,
    );
$cats = get_categories( $args );

神奇的参数是"深度"。