I have over 800 pages in WordPress which becomes a challenge trying to find a specific page to add it to the menu. View all works if you have only a few pages so the best option would be to search for the page to add it to the menu. The problem is that the search result only brings up 10 pages, I need it to return more results (say 30) so I can find the page that I am looking for, the page that I am looking for might be result number 22 but I can’t find it because it is not displayed, hope this makes sense.

Just a reminder that I want to increase the search results for “Admin -> Appearance -> Menus -> Search” and not “Admin -> Pages -> Search”

Any body can help me with what code to add to the functions.php file to increase the search results?

Thank you in advance
Tony

4 s
4

No need to change core files! Here is a hook (add in functions.php or simple plugin):

// filtering quick-menu-search results (this seems better than others at https://pastebin.com/raw/jRkJYAzE )
add_action( 'pre_get_posts', 'myFilter1', 10, 2 );
function myFilter1( $q ) {
    // example of $q properties: https://pastebin.com/raw/YK1uaE0M
    if(isset($_POST['action']) && $_POST['action']=="menu-quick-search" && isset($_POST['menu-settings-column-nonce'])){    
        // other parameters for more refinement: https://pastebin.com/raw/kZ7hwpyx
        if( is_a($q->query_vars['walker'], 'Walker_Nav_Menu_Checklist') ){
            $q->query_vars['posts_per_page'] =  30;
        }
    }
    return $q;
}

change 30 to whatever you want.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *