I'm writing a function to find the users next upcoming event (stored as CPT), chronologically.
If I use a normal query and do something like
'post_type' => 'ticket', // another CPT set up to act as ticket 'orderby' => 'meta_value_num', 'meta_key' => 'event_date', // currently just Ymd but can be changed to unix / whatever if neccesary. 'order' => 'ASC', 'posts_per_page' => 1, // changing to -1 to get all tickets 'meta_query' => array( array( 'key' => 'member', 'value' => $user_id //user ID stored as meta on ticket CPT ), array( 'key' => 'state', 'value' => 'complete' // to make sure is a confirmed & paid ticket ) )
That will find the
ticket post type that is the last chronologically in the list ie. the "most future" event.
What I'd love to do then is to put a filter through the results to remove all the tickets that are before today ( I've previously used if
$event_date >= date("Ymd") )
Then from those results use an opposite or a separate
orderby to get the first upcoming event.
Please comment if you need any more information. Happy to pastebin any extra code you feel you need.