I have a list of events on a clients website that show in a sidebar. When viewing the homepage you see one event and if you're anywhere else on the site you see two events in the sidebar. I am currently ordering them by using a meta_query compare that checks if the event is today or in the future.
What I would like to do is have the events show by closest to the current date first, then proceed up the chain until it finds one. Currently it appears to show events by furthest into the future instead. So if I have an event January 27th, 2012 and an event August 15th, 2012 it seems to show the August event.
The code I currently have is the following. I'd appreciate some advice on how to tweak it to get it to work the way I want. Please provide a little explanation with any code you post if possible, I'd like this to be a learning experience.
$totalPosts = 2; $args = array( 'post_type' => 'upcoming_courses', 'order' => 'ASC', 'orderby' => 'meta_value', 'suppress_filters' => true, 'posts_per_page' => $totalPosts, 'numberposts' => $totalPosts, 'meta_query' => array( array( 'key' => 'course_date', 'value' => date('Y-m-d'), 'compare' => '>=', 'type' => 'NUMERIC' ) ) ); $my_query = new WP_Query( $args );