admin管理员组文章数量:1122846
I need to get unique values of array to use in a filter. This is my code
<?php
$newsArgs = array(
'post_type' => 'sistemas-sanitarios',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1,
'post_parent' => 0,
'category' => 'categoria_sistemas_sanitarios',
'meta_query' => array(
array(
'key' => 'segmento_produto',
'value' => $linhas['id'],
'compare' => 'LIKE',
)
)
);
$filter_query = new WP_Query( $newsArgs );
?>
<ul id="filters" class="clearfix">
<?php
$taxonomy = 'categoria_sistemas_sanitarios';
$terms = get_terms( $taxonomy );
echo '<li><span class="filter-'. $title . ' active" data-filter="';
$li = ' ';
foreach ( $terms as $term) {
$li .= '.' . $term->slug.', ';
}
$li = rtrim($li, ', ');
echo $li;
echo '">Todos os Sistemas</span></li>';
while ( $filter_query->have_posts() ) : $filter_query->the_post();
$categoria = get_the_terms( $post->ID, 'categoria_sistemas_sanitarios' );
$categoriaSlug = $categoria[0]->slug;
$categoriaName = $categoria[0]->name;
echo '<li><span class="filter-'. $title . '" data-filter=".' . $categoriaSlug . '">' . $categoriaName . '</li>';
endwhile; wp_reset_postdata();
?>
</ul>
How can I do that? I tried to use array_unique() but didn't work.
Thanks!
I need to get unique values of array to use in a filter. This is my code
<?php
$newsArgs = array(
'post_type' => 'sistemas-sanitarios',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1,
'post_parent' => 0,
'category' => 'categoria_sistemas_sanitarios',
'meta_query' => array(
array(
'key' => 'segmento_produto',
'value' => $linhas['id'],
'compare' => 'LIKE',
)
)
);
$filter_query = new WP_Query( $newsArgs );
?>
<ul id="filters" class="clearfix">
<?php
$taxonomy = 'categoria_sistemas_sanitarios';
$terms = get_terms( $taxonomy );
echo '<li><span class="filter-'. $title . ' active" data-filter="';
$li = ' ';
foreach ( $terms as $term) {
$li .= '.' . $term->slug.', ';
}
$li = rtrim($li, ', ');
echo $li;
echo '">Todos os Sistemas</span></li>';
while ( $filter_query->have_posts() ) : $filter_query->the_post();
$categoria = get_the_terms( $post->ID, 'categoria_sistemas_sanitarios' );
$categoriaSlug = $categoria[0]->slug;
$categoriaName = $categoria[0]->name;
echo '<li><span class="filter-'. $title . '" data-filter=".' . $categoriaSlug . '">' . $categoriaName . '</li>';
endwhile; wp_reset_postdata();
?>
</ul>
How can I do that? I tried to use array_unique() but didn't work.
Thanks!
Share Improve this question asked Aug 21, 2018 at 0:26 Fellipe AbreuFellipe Abreu 11 Answer
Reset to default 0Is correct to do this way?
`<ul id="filters" class="clearfix">
<?php
$taxonomy = 'categoria_sistemas_sanitarios';
$terms = get_terms( $taxonomy );
$unique = array();
echo '<li><span class="filter-'. $title . ' active" data-filter="';
$li = ' ';
foreach ( $terms as $term) {
$li .= '.' . $term->slug.', ';
}
$li = rtrim($li, ', ');
echo $li;
echo '">Todos os Sistemas</span></li>';
while ( $filter_query->have_posts() ) : $filter_query->the_post();
$categoria = get_the_terms( $post->ID, 'categoria_sistemas_sanitarios' );
$categoriaSlug = $categoria[0]->slug;
$categoriaName = $categoria[0]->name;
if( ! in_array( $categoriaSlug, $unique ) ) :
$unique[0] = $categoriaSlug;
echo '<li><span class="filter-'. $title . '" data-filter=".' . $unique[0] . '">' . $unique[0] . '</li>';
endif;
endwhile; wp_reset_postdata();
?>
</ul>`
本文标签: custom taxonomyACFGet unique values of array
版权声明:本文标题:custom taxonomy - ACF - Get unique values of array 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304589a1932285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论