wp_nav_menu() not working on Custom Search Page

I know this is an old thread but the problem still exists. I think this is a bug. Default queries such as nav should not be affected in making custom search page. Anyways, this is how I fixed it:

function fix_nav_menu_in_search($query)
{
    if (is_search()) {
        $query->set('post_type', ['your_cpt', 'nav_menu_item']);
    }

    return $query;
}
add_filter('pre_get_posts', 'fix_nav_menu_in_search');

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)