我在我的网站上使用type_evenement
具有 5 个可能值(val_1、val_2、val_3、val_4、val_5)的选择字段 ( )的高级自定义字段
我还在自定义模板页面上使用 wp 查询来显示某个类别的帖子,所有帖子都使用“选择”自定义字段。
我正在尝试在此页面上显示所有选择值,但仅显示一次,因此我尝试使用 array_unique 删除双精度值,但它不起作用。
这是我为显示循环内的值而编写的代码,它显示所有值,即使是双精度值,例如,val_1、val_3、val_4、val_2、val_1、val_1...
<?php
// args
$today = date("Ymd");
$args = array (
'category' => 5,
'posts_per_page' => -1,
'meta_key' => 'debut_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'fin_date',
'compare' => '>=',
'value' => $today,
)
),
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php
$input = get_field('type_evenement');
echo($input);
?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
但是当使用 array_unique 时,不再显示任何内容:
<?php
$input = get_field('type_evenement');
$result = array_unique($input);
echo($result);
?>
我不明白我做错了什么,我知道 get_field 返回一个数组,所以我猜 array_unique 应该工作不?
如果有人可以帮助我,那就太好了!
多谢