admin管理员组文章数量:1402990
The following code pulls events from a custom post type that used Advanced Custom Fields, that is shown on an event listing page. It shows upcoming events as desired except when the event is on the current day. So if an event's start day was today it doesn't show.
For compare it had '>' and changed to '>=" which would presumably also then show dates that are on the current date but adding the = doesn't make a difference and I do just, "=" then nothing shows. Have tried changing OR to AND and didn't seem to make a difference either. The only thing that works is if I change the event date to be any date in the future (aka not today).
<?php
// Upcoming Events & Events Underday
$now = date('Y-m-d H:i:s');
$args = array(
'post_type' => 'events_post_type',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
'date_upcoming_clause' => array(
'key' => 'event_start_date',
'compare' => '>=',
'value' => $now,
'type' => 'DATETIME'
),
),
'orderby' => array(
'date_upcoming_clause' => 'ASC',
),
);
$the_query = new WP_Query($args);
?>
Update: Commenter noted to remove H:i:s and while that works then it would still show event as upcoming after it passes while it's the same day as event. But that helped me realized in the code I'm not doing a compare for the time. So I've added that but doesn't work at all (doesn't show any events). But getting closer! Updated code below:
<?php
// Upcoming Events & Events Underday
$now = date('Y-m-d');
$now2 = date('H:i:s');
$args = array(
'post_type' => 'events_post_type',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
'date_upcoming_clause' => array(
'key' => 'event_start_date',
'compare' => '>=',
'value' => $now,
'type' => 'DATETIME'
),
),
'time_upcoming_clause' => array(
'key' => 'event_end_time',
'compare' => '<=',
'value' => $now2,
'type' => 'DATETIME'
),
'orderby' => array(
'date_upcoming_clause' => 'ASC',
),
);
$the_query = new WP_Query($args);
?>
event_end_time in acf holds just the time and event start date holds just the date. Have tried all different things such as reversing the > < among other things but no luck. In ACF have it set to return m/d/y for date and g:ia for time. I've tried using those for $now and $now2 but doesn't seem to help.
本文标签: loopShow custom post type event if current day using ACF
版权声明:本文标题:loop - Show custom post type event if current day using ACF 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744647182a2617467.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论