My navigation menu started disappearing on category pages. First I suspected there was something with the header or menu location, I have double, triple checked everything and I was pulling my hair out trying to find a solution. Turns out, my attempt to order posts by a custom field interfered with the menu.

  if( ! $query->is_main_query()) return;

The key is the above line, and here is the rest of the code for example

add_filter( 'pre_get_posts', 'eo_custom_get_posts' );

function eo_custom_get_posts( $query ) {

  if( is_category()  || is_archive() ) { 
  if( ! $query->is_main_query()) return;
    $query->query_vars['orderby'] = 'meta_value_num';
    $query->query_vars['order'] = 'DESC';
    $query->query_vars['meta_key'] = 'lastupd';
  }
    return $query;
}

 

Bir cevap yazın

E-posta hesabınız yayımlanmayacak.