Hey Guys,
Can someone please tell me why this query is not returning any posts?
I have a custom post type called ‘Fixtures’ with a field called ‘date_time’. There are 2 posts with dates within the 7 days however they’re not showing?
<?php
// find date time now
$date_now = date('F j, Y g:i a');
$time_now = strtotime($date_now);
// find date time in 7 days
$time_next_week = strtotime('+7 day', $time_now);
$date_next_week = date('F j, Y g:i a', $time_next_week);
// query events
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'fixtures',
'meta_query' => array(
array(
'key' => 'date_time',
'compare' => 'BETWEEN',
'value' => array( $date_now, $date_next_week ),
'type' => 'DATETIME'
)
),
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'date_time',
'meta_type' => 'DATETIME'
));
if( $posts ): ?>
<h2>Upcoming events this week</h2>
<ul id="events">
<?php foreach( $posts as $p ): ?>
<li>
<strong>test</strong>: <?php the_field('home', $p->ID); ?> - <?php the_field('away', $p->ID); ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
date/time fields are stored in standard mySQL date format “Y-m-d H:i:s”