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

时间:2016-03-06 10:09:02

标签: wordpress categories

有没有办法获得几个类别的所有子类别?类似的东西:

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

1 个答案:

答案 0 :(得分:2)

这是不可能的,wordpress只是接受一个整数的所有它的类别子类。你必须分开让他们的孩子:

$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
}

希望它有所帮助!

相关问题