元查询选择 ACF 不返回当前日期的帖子

我正在尝试根据 ACF 选择(多个)一周中的几天(周一至周日)返回一个帖子类型。我使用 ACF Select 键 (show_days) 和当前日期的关系设置了一个元查询。var_dump 显示两个数组正在相互比较,但仍未显示节目(帖子类型)。


<?php


      $date = date('l');

      $shows = get_field('station_shows', false, false);

      $query = new WP_Query ( array(

        'post_type'       => 'shows',

        'posts_per_page'  => 1,

        'post__in'        => $shows,

        'post_status'     => 'publish',

        'meta_query' => array(

            'relation' => 'AND',


           array (

                       'key'           => 'show_days',

                       'value'     => array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'),

                       'compare'  => 'IN',

                     ),

           array (

                       'key'       => 'date',

                       'value'     => $date,

                       'compare'   => '=',

                       'type'      => 'DATE',

                     ), 


            )));

       if ( $query->have_posts() ) { while( $query->have_posts() ) {

       $query->the_post();

       echo '<div class="onAir"><h3>Currently On Air: ';

       the_title();

       if (get_field('dj', $query->ID)) {

                 $dj = get_field('dj');

                 echo ' w/ ';

              echo $dj;

          }

           echo '</h3></div>';


          } wp_reset_postdata();

        }


 ?>

不知道是不是数据库元值不对应。我什至尝试过 unserialize() 数组,但它仍然返回相同的数组值。任何帮助,将不胜感激。谢谢!


蝴蝶刀刀
浏览 105回答 1
1回答

米琪卡哇伊

好吧,我想通了。此查询与时间查询结合使用,因此我将整个代码放在一起。它正在将当前时间与两个自定义字段(时间范围)进行比较,以及哪些日期被选中(复选框)。因此,如果是星期二下午 4 点,它只会显示时间范围为下午 4 点,并且如果星期二被选中。此外,它还有一个关系字段,我可以在其中将节目分配给某些广播电台。所以在 Radio Station 帖子类型页面上,广播功能将根据一天中的时间显示!&nbsp;<?php&nbsp; &nbsp; &nbsp; $time = current_time('H:i:s');&nbsp; &nbsp; &nbsp; $date = strftime("%u", time());&nbsp; &nbsp; &nbsp; $shows = get_field('station_shows', false, false);&nbsp; &nbsp; &nbsp; $query = new WP_Query ( array(&nbsp; &nbsp; &nbsp; &nbsp; 'post_type'&nbsp; &nbsp; &nbsp; &nbsp;=> 'shows',&nbsp; &nbsp; &nbsp; &nbsp; 'posts_per_page'&nbsp; => 1,&nbsp; &nbsp; &nbsp; &nbsp; 'post__in'&nbsp; &nbsp; &nbsp; &nbsp; => $shows,&nbsp; &nbsp; &nbsp; &nbsp; 'post_status'&nbsp; &nbsp; &nbsp;=> 'publish',&nbsp; &nbsp; &nbsp; &nbsp; 'orderby'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=> 'meta_value',&nbsp; &nbsp; &nbsp; &nbsp; 'meta_key'&nbsp; &nbsp; &nbsp; &nbsp; => 'show_days',&nbsp; &nbsp; &nbsp; &nbsp; 'meta_query' => array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'relation' => 'AND',&nbsp; &nbsp; &nbsp; &nbsp; array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'key'&nbsp; &nbsp; &nbsp; &nbsp;=> 'start_time',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'value'&nbsp; &nbsp; &nbsp;=> $time,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'compare'&nbsp; &nbsp;=> '<=',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'type'&nbsp; &nbsp; &nbsp; => 'TIME',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),&nbsp; &nbsp; &nbsp; &nbsp; array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'value'&nbsp; &nbsp; &nbsp;=> $time,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'key'&nbsp; &nbsp; &nbsp; &nbsp;=> 'end_time',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'compare'&nbsp; &nbsp;=> '>=',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'type'&nbsp; &nbsp; &nbsp; => 'TIME',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),&nbsp; &nbsp; &nbsp; &nbsp;))&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; $days = the_field('show_days');&nbsp; &nbsp; &nbsp; if ($query->have_posts()&nbsp; && $days = $date&nbsp; )&nbsp; { while( $query->have_posts() ) {&nbsp; &nbsp; &nbsp; &nbsp; $query->the_post();&nbsp; &nbsp; &nbsp; &nbsp; echo '<div class="onAir"><h3>Currently <span>On Air</span> : ';&nbsp; &nbsp; &nbsp; &nbsp; the_title();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo '</h3></div>';&nbsp; &nbsp;}&nbsp; &nbsp;wp_reset_postdata();&nbsp; }&nbsp;?>
打开App,查看更多内容
随时随地看视频慕课网APP