1

Wrote this function to display the menu items into search, it is working, on search it includes the menu items but the link to them is not correct, by default search items contain link to Permalink/slug

There are some external links in menu items so i want the links to be included correctly,

 function my_multisite_search($query) {
    if(!is_admin() && $query->is_main_query() && $query->is_search) {
        $query->set('multisite', 1);
        $query->set( 'post_type', array( 'post', 'page', 'attachment', 'nav_menu_item'));
        $query->set( 'post_status', array( 'publish', 'inherit' ) );

    }
}
add_action('pre_get_posts', 'my_multisite_search');
2
  • Are you using WordPress Multi-site ?
    – Nestsouls
    Commented Oct 13, 2017 at 15:56
  • @Nestsouls, Yes, but i think that should not effect the search behavior. Commented Oct 13, 2017 at 15:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.