Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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'
              );
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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(
        array(
            'key' => 'color',
            'value' => 'blue',
            'compare' => 'NOT LIKE'
        ),
        array(
            'key' => 'price',
            'value' => array( 20, 100 ),
            'type' => 'numeric',
            'compare' => 'BETWEEN'
        )
    )
 );
$query = new WP_Query( $args );

See Custom Field Parameters for details.

share|improve this answer
    
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 '11 at 21:35
    
@Zoolander you are missing array() around second set of field conditions. –  Rarst May 11 '11 at 21:38
    
You are AWESOME. You just made my day with helping me to make this work. THANK YOU!!! –  Zoolander May 11 '11 at 21:41

Your Answer

 
discard

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.