カスタムフィールドテンプレートでチェックボックスにチェックを入れた記事のみを表示する方法

カスタムフィールドテンプレートのチェックボックス項目で
チェックを入れた記事のみを表示する方法です。
例:
フィールド名「menu-type」で選択肢「food」にチェックを入れた記事を表示します。

サンプルコード
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php $args = array( 'post_type' => 'menu', 'meta_query' => array( array( 'key' => 'menu-type', //フィールド名 'value' => array('food'), //選択肢 'compare' => 'IN', ), ), 'posts_per_page' => -1, 'paged' => $paged, ); ?> <?php $query = new WP_Query( $args ); ?> <?php if($query -> have_posts()): ?> <ul class="me_school_list01"> <!-- the loop --> <?php while($query -> have_posts()): $query->the_post();?> <li> </li> <?php endwhile; ?> <!-- end of the loop --> </ul> <?php endif; ?> <?php wp_reset_postdata(); ?> |
![MARKLEAPS[マークリープス]](https://markleaps.com/blog/wp-content/themes/mkl/images/00_logo.png)

![[WordPress] プラグイン「WP ALL Import」で既存記事を一括更新(CSV上書き)する方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import_update-500x254.jpg)
![[WordPress] CSVで記事を一括インポート-プラグイン「WP ALL Import」の使い方](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-all-import-500x254.jpg)
![[WordPress] 記事への画像挿入方法](https://markleaps.com/blog/wp-content/uploads/2025/10/pic_manual_mainimg-500x254.png)
![[WordPress] カテゴリーとタグの違いと設定方法](https://markleaps.com/blog/wp-content/uploads/2025/10/wp-category-tag-500x254.jpg)