I pre get posts for a events archive page: http://www.netzwerk-leipziger-freiheit.de/veranstaltungen/
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() ){
return $query;
}
// only modify queries for 'event' post type
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'events' ) {
$query->set('orderby', 'meta_value_num');
$query->set('meta_key', 'vdatum');
$query->set('order', 'ASC');
}
// return
return $query;
}
add_action('pre_get_posts', 'my_pre_get_posts');
This will all work but if you select a single event the order is not depend on the pre get post query. And when you go to the last event on the left button on an event it ends in a 404.
I will be happy for any solution.