[英]Don't display WordPress posts if time has passed using WP_Query
我有一個自定義的日程表類型,可以在Timeslot的自定義字段中添加“事件”。 此自定義字段是使用ACF Pro的轉發器。 它包含日期,開始時間和結束時間。 日期選擇器和時間選擇器。
在主頁上,我有一個圖像滑塊,可以拉入圖片和事件標題,並且僅按時間順序顯示“今天”事件。 我現在想做的是不顯示已過去的事件。 因此,例如,如果當前時間是下午14:00,則在該時間之前結束的所有節目都不會顯示。 如果該節目在下午13:00開始並在下午15:00結束,則該節目仍將顯示,並且將首先出現。 我希望這是有道理的?!
到目前為止,這是我的WP_Query,但是經過幾次嘗試,我無法弄清楚如何對其進行修改以使其按要求工作:
<?php
$args = array(
'post_type' => 'schedule',
'posts_per_page' => '-1',
'meta_query' => array(
'relation' => 'AND',
'date_clause' => array(
'key' => 'schedule_time_slot_%_schedule_show_date',
'compare' => '=',
'value' => $day,
),
'time_clause' => array(
'key' => 'schedule_time_slot_%_schedule_show_start_time',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'date_clause' => 'ASC',
'time_clause' => 'ASC',
)
);
<?php
$args = array(
'post_type' => 'schedule',
'posts_per_page' => '-1',
'meta_query' => array(
'relation' => 'AND',
'date_clause' => array(
'key' => 'schedule_time_slot_%_schedule_show_date',
'compare' => '=',
'value' => $day,
),
'time_clause' => array(
'key' => 'schedule_time_slot_%_schedule_show_start_time',
'compare' => '>=',
'value' => time(),
),
),
'orderby' => array(
'date_clause' => 'ASC',
'time_clause' => 'ASC',
)
);
注意time_clause參數中的更改。 因此,僅在time_clause等於或晚於現在的時間時顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.