本文介绍了使用get_categories()获取几个类别的子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以获取几个类别的所有子类别?像这样:
Is there a way to get all sub categories of several categories? something like:
get_categories( array( 'child_of'=>array(10,3,8) );
推荐答案
不可能,wordpress在其所有获得类别子项的函数中仅接受一个整数.您必须分别带他们的孩子:
It's not possible, wordpress just accepts one integer in all it's functions that get categories children. You'll have to get their children separately:
$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
}
希望有帮助!
这篇关于使用get_categories()获取几个类别的子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!