admin管理员组

文章数量:1125044

I have a custom query to order and display posts in my functions.php, and I noticed that the navigation menu disappear in those categories!

function my_filtro_ed_ordine( $query ) {
    
    if ( is_admin()) {
        return $query;    
    }

    
if ( (isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'viaggi-di-gruppo') || ( is_category(array(46, 4, 5, 6, 7, 8, 123, 161)) )) {
        
        $expire = date('Ymd');
        $query->set( 'meta_query', [
          'relation' => 'OR',
          [
           'key'     => 'partenza_al',
           'value'   => $expire,
           'compare' => '>=',
           'type'    => 'NUMERIC',
          ],
          [
           'key'     => 'partenza_al',
           'compare' => 'NOT EXISTS',
          ],
        ]);
        
        $query->set('orderby', 'meta_value');   
        $query->set('meta_key', 'partenza_al');  
        $query->set('order', 'ASC'); 
$query->set('meta_type', 'DATETIME');
    }
    
    return $query;
}
add_filter( 'pre_get_posts', 'my_filtro_ed_ordine' );

I don't know why the menu disappear, does anyone have an idea why the menu disappears? Any help will be really appreciated, thank you!

PS: I already tried to add wp_nav_menu(array('theme_location' => 'primary-menu')); in the if, but the site returns a critical error.

本文标签: postsWordpress menu disappears in category pages