wordpressのSCF(スマートカスタムフィールド/smart custom field)の値が重複したらまとめる方法を探しています。
array_uniqueを使用してもエラーで表示されないため、困っています。
知識不足で大変恐縮ですが、ご教授いただければと思っています。
(度々こちらで質問させていただき、学ばせていただいております)
■スマートカスタムフィールド上の設定
・CPTUIで「search」登録
・繰り返し設定、フィールドグループ名「checkbox_custom」、フィールドタイプ「テキスト」、フィールド名前「checkbox_item」
■コード
【index.php】のページで下記、var_dumpを使用して確認した際のコードです。
重複しているものは各記事に記入している内容です。
<?php $args = array( 'post_type' => 'search', 'post_status' => 'publish', 'posts_per_page' => -1 ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : ?> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php $checkbox_custom = SCF::get('checkbox_custom'); foreach( $checkbox_custom as $costom => $value){ echo "<pre>"; $results = $value['checkbox_item']; var_dump($results); echo "</pre>"; } ?> <?php endwhile; ?> <?php endif; wp_reset_postdata(); ?> </div> コード
下記、出力した内容になります。
出力テスト
string(12) "テスト1"
string(12) "テスト1"
string(12) "テスト2"
string(12) "テスト3"
string(12) "テスト1"
string(0) ""
string(12) "テスト2"
string(12) "テスト6"
string(0) ""
string(0) ""

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/25 07:14
2022/02/28 03:23