WP_Query with dates meta_query not returning any custom posts

  php, wordpress

I am trying to create a loop that will filter a long list of features by only the fixtures that are happening at home, and in the next 2 weeks. The following code seems to ignore the anything past the first 10 fixtures. The loop worked when I was testing with ~8 fixtures. But when I added all fixtures the loop doesn’t return anything.

Is there something wrong with this loop that I’m not seeing?

Thanks!

<?

// Find current date time.
$date_now = date('Y-m-d H:i:s');
$time_now = strtotime($date_now);

// Find date & time in 7 days.
$time_next_week = strtotime('+7 day', $time_now);
$date_next_week = date('Y-m-d H:i:s', $time_next_week);

$args = array(
  'post_type' => 'fixtures',
  'posts_per_page' => -1,
  'meta_query' => array(
    array(
      'key' => 'fixture_kickoff',
      'compare' => 'BETWEEN',
      'value' => array($date_now, $date_next_week),
      'type' => 'DATETIME'
    ),
    array(
      'key' => 'home_or_away',
      'value' => 'home',
      'compare' => '='
    )
  ),
  'order' => 'ASC',
  'orderby' => 'meta_value',
  'meta_key' => 'fixture_kickoff',
  'meta_type' => 'DATETIME'
);

$fixturesLoop = new WP_Query($args);

if( $fixturesLoop->have_posts() ):

  while ( $fixturesLoop->have_posts() ) : $fixturesLoop->the_post(); ?>

<ul>
  <li><?php the_title(); ?></li>
</ul>

<?php endwhile; ?>


<?php else : ?>

    <p>There are no tickets on sale at the moment. Check back at least 7 days before the next home game.</p>

<?php endif; wp_reset_postdata(); ?>

Source: Ask PHP

LEAVE A COMMENT