我在这里需要一些帮助,我试图在我的自定义分类中只获得分类法的子元素。我成功检索项目和父类别,但我只需要孩子,它适用于一些帖子,我不知道为什么和如何。
以下是我尝试过的代码:
$terms = get_terms('project_countries');
foreach($terms as $term) {
$posts = get_posts(array(
'post_type' => 'projects',
'tax_query' => array(
array(
'taxonomy' => 'project_countries',
'field' => 'slug',
'hierarchical' => 0,
'include_parent' => false,
'terms' => $term->slug
)
),
'numberposts' => -1
));
foreach($posts as $post) {
echo $term->name;
$allname=$post->post_title.'</br>';
print_R($allname);
}
}