WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I saw a request for a simple 7 day event calendar that always starts with today.

I have a custom meta box called opening-time that gets a YYYY-MM-DD input.

For now this is what I have, and its not working.

It only outputs 2011-11-17 today is 11-11-2011 so that is wrong. It also must have a php error because none of the blog outputs either.

Thank you in advance.

<ul id="days_header">
    $today = date("o-m-d");
 $future = strtotime ( '+6 days' , strtotime ( $today ) ) ;
 $future = date ( 'o-m-d' , $future );
 $event_query = new WP_Query(
  'post_type'   => 'event',
  'meta_key'    => 'opening_time',
  'orderby'     => 'meta_value',
  'order'       => 'asc',
  'meta_query'  => array(
      'key'     => 'opening_time',
      'value'   => array($today,$future),
      'compare' => 'BETWEEN',
      'type'    => 'DATE'
<?php for ($i=0; $i<7; $i++):
$thedate = strtotime ( '+'.$i.' day' , strtotime ( $today ) ) ;
$thedate = date ( 'o-m-d' , $thedate ); ?>

<?php echo $thedate; ?>
<?php if ($event_query->have_posts()) : while ($event_query->have_posts()) :  $event_query->the_post();?>
  <?php if(meta('opening_time') == $thedate) :?>
    <?php the_title(); ?>
    <?php else: ?>
      No Events Today

  <?php endif; ?>
<?php endwhile; endif; rewind_posts(); ?> 

share|improve this question

I haven't had much success in the past using the BETWEEN comparison with meta queries. You might have better luck by replacing your meta query with a >= and <= comparison:

'meta_query'  => array(
    'key'     => 'opening_time',
    'value'   => $today,
    'compare' => '>=',
    'type'    => 'DATE'
    'key'     => 'opening_time',
    'value'   => $future,
    'compare' => '<=',
    'type'    => 'DATE'

Depending on your application you may want to tune the results a bit by dropping the "or equal to" from one or both of the statements (right now it's being very forgiving).

As for the PHP error, the code you provided doesn't end the "for" loop with an endfor. Have you checked your PHP error log? You can also try turning on WP_DEBUG in your wp-config.php file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.