I recently upgraded WordPress from 3.0.x to 3.1.2. I had set it up to use custom post types before the upgrade. I need make a list of events that are occurring that started in the past until they occur.

For example, if an event started today at Noon, it should show up in this list until it ends, which could be tomorrow at 6:00 PM.

Can someone tell me how to modify this query so it will get custom posts that occur between the start and end date (multiple keys)?

$args = array ('post_type'      => 'events',
               'meta_key'       => 'end_date_value',
               'meta_compare'   => '>',
               'meta_value'     => $current_time,
               'orderby'        => 'meta_value',
               'order'          => 'ASC'

1 Answer 1


Here is example from Codex on using BETWEEN with new format of meta query, which covers multiple fields as well:

$args = array(
    'post_type' => 'product',
    'meta_query' => array(
            'key' => 'color',
            'value' => 'blue',
            'compare' => 'NOT LIKE'
            'key' => 'price',
            'value' => array( 20, 100 ),
            'type' => 'numeric',
            'compare' => 'BETWEEN'
$query = new WP_Query( $args );

See Custom Field Parameters for details.

  • Thanks for the help! Can you take a look at my update above and see if you can spot why it's not returning any results? The start date is set to a timestamp of May 11, 2011 13:00 and the end date is May 13, 2001 12:00.
    – Zoolander
    May 11, 2011 at 21:35
  • @Zoolander you are missing array() around second set of field conditions.
    – Rarst
    May 11, 2011 at 21:38
  • You are AWESOME. You just made my day with helping me to make this work. THANK YOU!!!
    – Zoolander
    May 11, 2011 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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