Pre get posts for single post


I pre get posts for a events archive page:

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.

, , , Rene 6 years 2016-11-11T06:37:28-05:00 0 Answers 73 views 0

Leave an answer