wordpress navigation menu will not be displayed on an archive page

Update

After searching the forums for this question, I’ve noticed that some people also have this bug when changing the sorting order of queries by using the pre_get_posts WP hook. If you change the order for all post types (that includes menu items) your menu items might not appear properly as they are posts themselves.

This can be solved by including an if statement checking if the current query is the main query. For example, if you have this function:

// Change sort order of archive page to alphabetical
add_action( 'pre_get_posts', 'my_change_sort_order');
    function my_change_sort_order($query){
        if (is_archive() && is_post_type_archive( 'menschen' )):
           //Set the order ASC or DESC
           $query->set( 'order', 'ASC' );
           //Set the orderby
           $query->set( 'meta_key', 'nachname' );
           $query->set( 'orderby', 'meta_value' );
           $query->set( 'posts_per_page', -1 );
        endif;
    };

You would have to add && $query->is_main_query() to the if statement. This means that the function is ignored for all queries but the main one, so menu items don’t disappear.

For more info you can vist this stackoverflow answer.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top