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