There is no user menu on the search page

I scratched my head over this, so in advance for any help in advance. Very much appreciated.

I have a menu in WP 3.0.1 that I call in header.php using:

wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );

It is displayed perfectly on each page separately from the search results. The search.php file starts with the standard one get_header();, so should it be code wp_nav_menucorrectly? But nothing is wrapped conditional or not.

The HTML output should look like this:

<div class="menu-header">
    <ul id="menu-main-menu" class="menu">
        <li class="menu-item">
            <a>Link 1</a>
        </li>
        <li class="menu-item">
            <a>Link 2</a>
        </li>
    </ul>
</div>

But instead, it comes to <ul>and does not output any <li>s:

<div class="menu-header">
    <ul id="menu-main-menu" class="menu">
    </ul>
</div>

The strangest thing. Has anyone else come across this before? Is it too late and am I missing something obvious?

+3
3

@ZoulRic , Media Library. , :

if( !is_admin() )

, :

function menu_fix_on_search_page( $query ) {
   if(is_search()){
       $query->set( 'post_type', array(
        'attachment', 'post', 'nav_menu_item', 'film', 'music'
          ));
         return $query;
         }
   }
if( !is_admin() ) add_filter( 'pre_get_posts', 'menu_fix_on_search_page' );
+4

, , , , , , , , "nav_menu_item", .

+4

:

function menu_fix_on_search_page( $query ) {
    if(is_search()){
        $query->set( 'post_type', array(
         'post', 'nav_menu_item'
            ));
          return $query;
    }
}
add_filter( 'pre_get_posts', 'menu_fix_on_search_page' );

functions.php .

+4

Source: https://habr.com/ru/post/1775800/


All Articles