実現したいこと
WordPressでカスタム投稿(カスタムタイプ名はschedule)を作成し、カスタムフィールドの特定チェックボックスにチェックが付いた際、ループ出力から除外をしたいのですが、何故か空出力になってしまいます。
(trueの時はチェックボックスがついた記事が出力されます)
実際のコード
php
1//functions.php 2 3add_action('admin_menu', 'add_custom_field'); 4function add_custom_field(){ 5 add_meta_box('custom_item01', '詳細項目', 'custom_item01', 'team', 'normal'); 6} 7 8 9function custom_item01(){ 10 global $post; 11 if (get_post_meta($post->ID, 'sample', true) == "is-on") { 12 $sample_check = "checked"; 13 } 14 echo '<form method="post" action="admin.php?page=site_settings"> 15 <label for="sample">試合中止</label> 16 <input id="sample" type="checkbox" name="sample" value="is-on" ' . $sample_check . '> 17 </form>'; 18 19 echo '<input type="date" name="custom_item01_2" value="' . get_post_meta($post->ID, 'custom_item01_2', true) . '"/>'; 20} 21 22 23add_action('save_post', 'save_custom_field'); 24function save_custom_field($post_id){ 25 if (isset($_POST['sample'])) { 26 update_post_meta($post_id, 'sample', $_POST['sample']); 27 } else { 28 delete_post_meta($post_id, 'sample'); 29 } 30 if (isset($_POST['sample'])) { 31 update_post_meta($post_id, 'custom_item01_2', $_POST['custom_item01_2']); 32 } else { 33 delete_post_meta($post_id, 'custom_item01_2'); 34 } 35}
php
1//page.php 2 3<?php $args = array( 4 'posts_per_page' => 1, 5 'post_type' => 'schedule', 6 'post_status' => 'publish', 7 'meta_query' => array( 8 array( 9 'key' => 'custom_item01_2', 10 'value' => date('Y-m-d'), 11 'compare' => '<=', 12 ), 13 array( 14 'key' => 'sample', 15 'value' => "is-on", 16 'compare' => '!=', 17 ), 18 ), 19 'meta_key' => 'custom_item01_2', 20 'orderby' => 'meta_value', 21 'order' => 'desc' 22); 23$the_query = new WP_Query($args); 24if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?> 25 <p><?php the_title(); ?></p> 26<?php endwhile; 27endif; 28wp_reset_postdata(); ?>
発生している問題・エラーメッセージ
上記、page.phpでループ設定をしたところ、チェックボックスがついてない記事が出力してほしいのに空出力になってしまいます。
有識者の方々、どうかご助力の程お願いいたします・・・。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/24 23:12