I am using an events plugin and struggling to get my database query to be perfect. The query is on the event-single.php template. What I need the query to do:
- Query the "events" custom post type for upcoming events
- Sort by
_event_start_datemeta_key to show earliest date (nearest event)
- Not display PAST events
- If "current event", show next nearest event
Here's my current $args.
<?php $args = array( 'post__not_in' => array($donotrepeat), "post_type" => 'event', 'meta_key' => '_event_start_date', // name of custom field 'orderby' => 'meta_value_num', "order" => 'ASC', "posts_per_page" => 1 ); ?>
$donotrepeat = get_the_ID();
So far, the query successfully
- Queries custom post type
- Ignores the "current" event
- Sorts by earliest date.
I cannot figure out how to ignore 'past' dates though. There is another meta key 'scope' created by this plugin that contains values like 'past' and 'future' - so that could be promising.
I've tried using meta_query to sort through the past date issue, but I just can't seem to get it to work. I think this is probably the way to go, but I'm open to other ideas. I'm sure this isn't THAT difficult... can anyone help?