使用 get_categories() 获取多个类别的子类别

get sub categories of several categories with get_categories()

有没有办法获取几个类别的所有子类别?类似于:

get_categories( array( 'child_of'=>array(10,3,8) );

不可能,wordpress 在其所有获取类别的函数中只接受一个整数 children。您必须单独获取他们的 children:

$terms = array();
$taxonomy = 'category';
$parents = array(10, 3, 8);
foreach ($parents as $parent) {
    $terms = array_merge($terms, get_categories(array('child_of'=> $parent)));
}

foreach ($terms as $term) {
    // your code here
}

希望对您有所帮助!