亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

元查詢選擇 ACF 不返回當前日期的帖子

元查詢選擇 ACF 不返回當前日期的帖子

PHP
蝴蝶刀刀 2022-12-23 15:08:19
我正在嘗試根據 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() 數組,但它仍然返回相同的數組值。任何幫助,將不勝感激。謝謝!
查看完整描述

1 回答

?
米琪卡哇伊

TA貢獻1998條經驗 獲得超6個贊

好吧,我想通了。此查詢與時間查詢結合使用,因此我將整個代碼放在一起。它正在將當前時間與兩個自定義字段(時間范圍)進行比較,以及哪些日期被選中(復選框)。因此,如果是星期二下午 4 點,它只會顯示時間范圍為下午 4 點,并且如果星期二被選中。此外,它還有一個關系字段,我可以在其中將節目分配給某些廣播電臺。所以在 Radio Station 帖子類型頁面上,廣播功能將根據一天中的時間顯示!


 <?php

      $time = current_time('H:i:s');

      $date = strftime("%u", time());

      $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',

        'orderby'         => 'meta_value',

        'meta_key'        => 'show_days',

        'meta_query' => array(

            'relation' => 'AND',

        array(

                  'key'       => 'start_time',

                  'value'     => $time,

                  'compare'   => '<=',

                  'type'      => 'TIME',

            ),

        array(

                  'value'     => $time,

                  'key'       => 'end_time',

                  'compare'   => '>=',

                  'type'      => 'TIME',

            ),



       ))


        );

        $days = the_field('show_days');

      if ($query->have_posts()  && $days = $date  )  { while( $query->have_posts() ) {

        $query->the_post();


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

        the_title();

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


   }

   wp_reset_postdata();

  }

 ?>


查看完整回答
反對 回復 2022-12-23
  • 1 回答
  • 0 關注
  • 89 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號