如何排除子术语帖子显示在父术语帖子输出中??现在,它在父项和子项输出中重复。
//Function to display posts grouped by taxonomies
function display_posts_per_taxonomies($parent_term, $post_type = \'beat_posts\', $taxonomy = \'beats\'){
$parent_posts = get_posts(array(
\'tax_query\' => array( array(
\'taxonomy\' => $taxonomy,
\'field\' => \'slug\',
\'terms\' => $parent_term
)),
\'post_type\' => $post_type
));
echo \'<ul>\';
foreach($parent_posts as $post){
echo "<li>{$post->post_title}</li>";
}
$children_terms = get_terms($taxonomy, array(
\'parent\' => get_term_by(\'slug\', $parent_term, $taxonomy)->term_id
));
foreach($children_terms as $term){
echo \'<li>\';
display_posts_per_taxonomies($term->slug, $post_type, $taxonomy);
echo \'</li>\';
}
echo \'</ul>\';
}
下面是我想摆脱的。<ul>
<li>adsf</li>
<li>ergerg</li> <---get rid of this one (duplicate)
<li>asdfasdfsdf</li> <---get rid of this one (duplicate)
<li>rthhdhdfhdhdfhdfg</li>
<li>
<ul>
<li>ergerg</li>
<li>asdfasdfsdf</li>
</ul>
</li>
</ul>