I need to grab a list of current events. The events have a start and end date so I need to be able to select a range as opposed to just getting any list of events that have an end date that is after today's date.

Does anyone have any suggestions as to how to do this? (from what I've read there doesn't seem to be a way to use multiple "meta_key" and "meta_compare" values, but there must be a way some how)

Here's an example of what I'm using in my arguments, but I need to also do this for the start date as well:

'meta_key' => 'end_date_value', 'meta_compare' => '>', 'meta_value' => $todaysDate,

You can use your current code to create the query and then in your loop run a check before displaying the events something like

query_posts('meta_key' => 'end_date_value', 'meta_compare' => '>', 'meta_value' => $todaysDate);

 while ( have_posts() ) : the_post();
   $post_custom = get_post_custom($post_id);
   if ($startDate < $post_custom['start_date_value']){
    //your loop here


keep in mind that this is not well coded way to do this ,I would probably create a better sql query or use "posts_where" hook.

but its a start


Not quite efficent, but you may do two query.

One that extract the events that have a date greater than the startDate, and the other tha have the end time lower than your end data.

Then, you can do an array_intersect() the two arrays.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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