type_evenement
ウェブサイトで高度なカスタム フィールドを使用しており、5 つの可能な値 (val_1、val_2、val_3、val_4、val_5) を持つ選択フィールド ( ) を使用しています。
また、カスタム テンプレート ページで wp クエリを使用してカテゴリから投稿を表示しています。すべての投稿は「選択」カスタム フィールドを使用します。
このページにすべての選択値を表示しようとしていますが、一度しか表示されないため、array_unique を使用して double 値を削除しようとしていますが、機能していません。
これは、ループ内の値を表示するために私が書いたコードです。たとえば、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 は no で動作するはずです。
誰かがこれで私を助けることができればいいです!
どうもありがとう