我得到了一个列表类别名称的基础上,哪个标签是 Select 在WordPress,代码所有的工作和返回的类别列表,但我不能得到代码,以停止重复的类别名称.
请查看下面的代码:
<?php
// Get the categories
$terms = get_terms( array(
'taxonomy' => 'category',
'hide_empty' => 0,
'parent' => $catparid,
) );
// Loop through them
foreach($terms as $term) {
// Get the posts in that category with the required tag
$args = array(
'category_name' => $term->name,
'tax_query' => array(
array(
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $cattagfilter
)
)
);
$posts_array = get_posts( $args );
foreach ($posts_array as $value) {
$cattest = $term->name;
echo '<p><a href="/category/case-stuides/' .$term->slug. '">' .$term->name. '</a></p>';
}
}
?>
请参见下面的屏幕截图,它显示了类别名称列表中发生的事情.
我试过使用array_unique,但它不工作,除非我做了一些错误的事情或把它放在错误的地方,我感谢任何帮助.