Display upcoming events then past events
-
Hello,
I would like to sort a list of events by first displaying upcoming events, then past events (from the least old to the oldest).I tried this way :
add_action( 'pre_get_posts', 'custom_query_vars' ); function custom_query_vars( $query ) { if ( !is_admin() && $query->is_main_query()) { if ( in_array ( $query->get('post_type'), array('spectacles') ) ) { $query->set( 'post_status', 'publish' ); $today = date('Ymd'); $meta_query = array( 'relation' => 'OR', 'query_one' => array( 'key' => 'date', 'value' => $today, 'compare' => '>=' ), 'query_two' => array( 'key' => 'date', 'value' => $today, 'compare' => '<' ), ); $query->set( 'meta_query', $meta_query ); $query->set( 'orderby', array( 'query_one' => 'ASC', 'query_two' => 'DESC' ) ); } } return $query; }
But it doesn’t work ??
Do you have an idea ?
Thank you in advance !
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Display upcoming events then past events’ is closed to new replies.