Leave a Reply

1 comment

  1. For this to work reliably, the date format in the database should be yyyy-mm-dd. Comparison type should be DATE or NUMERIC. If you take the date of 25-04-2012 in present format and compare it numerically to the date 26-04-1986, you can see what the issue will be: 25042012 < 26041986

    ALso- if you’re doing these queries in addition to your main loop, use a new instance of WP_Query.

    EDIT-

    there were a few errors you didn’t fix. note that this still won’t work quite right until you fix the date format.

    <?php
    $today = date('m/d/Y', strtotime('+2 hours'));
    $the_query = new WP_Query( array(
      'post_type' => 'events',
      'posts_per_page' => 5,
      'meta_key' => 'start_date',
      'orderby' => 'meta_value',
      'order' => 'ASC',
      'meta_query' => array(
      array(
        'key' => 'start_date',
        'value' => $today,
        'compare' => '>=',
        'type' => 'DATE'
      ))
    ));
    ?>