6

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

2
  • I dont understand.. (sorry) - do you means the regular search results displayed after you enter a search query only returns 10 results and you have "next" "previus" buttons? Commented Mar 28, 2012 at 16:01
  • Hi Sagive SEO. @Sagive SEO Thanks for getting back to me "Admin -> Appearance -> Menus -> Search" only gives 10 results by default, there isn't a next or previous button as when you do a regular search in the admin area under "Admin -> Pages -> Search" See image attached:[link] (dontremove.s3.amazonaws.com/appearance-menus-search.png ) Commented Mar 29, 2012 at 13:51

5 Answers 5

10

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.

3
  • Still relevant in 2020. Commented Sep 8, 2020 at 19:59
  • 1
    so useful, just took me 30 minutes to find this because every Google search tried to teach me how to set up a search bar in WordPress. The basic sorting of the default search results SUCKS. I have a page called rewilding, with a slug called rewilding, and searching rewilding doesn't show it in the results. Thank you! Commented Jan 19, 2022 at 16:45
  • 1
    This works nicely -- it's insane that you can have a page named "About Us", search for it, and 50 other pages show up but "About Us" is missing. How is it THIS bad still, after all these years? Commented Feb 19 at 21:34
1

I used @T.Todua's helpful answer as a starting point but also wanted to solve the fundamental issue: WordPress's default menu search relevance is terrible. It's helpful to see more results but ideally, the ones at the top would be the ones you are looking for.

Fortunately, WordPress core has a relevance option for WP_Query's orderby parameter, so I'm using that in conjunction with increasing the number of results:

/** * Improve menu search by sorting by relevance and increasing the number of posts returned. * * @param WP_Query $query The WP_Query object. * @return void */ function se_improve_menu_search( $query ) { // Check if the query is for the menu quick-search. If not, return early. if ( ! is_admin() || empty( $_POST['action'] ) || 'menu-quick-search' !== $_POST['action'] || empty( $_POST['menu-settings-column-nonce'] ) || empty( $query->query_vars['walker'] ) || ! is_a( $query->query_vars['walker'], 'Walker_Nav_Menu_Checklist' ) ) { return; } // Sort by relevance. $query->set( 'orderby', 'relevance' ); // Increase the number of posts returned. $query->set( 'posts_per_page', 30 ); } add_action( 'pre_get_posts', 'se_improve_menu_search' ); 
1
  • 1
    This answer worked for me. Thanks @Sarah Lewis Commented Apr 22 at 22:40
0

ok... sorry - i have searched and as for now i cant find a way to hard code this option... hope someone of the many wordpress experts here would help reach a hard coded solution.

For now i would reccomend you use the built in Search capability of your browser to do a simple search for the desired name...

See Image:
enter image description here

3
  • Thanks for the feedback. I know what the URL is for the page but can't add it to the menu without finding it in the "Most Rent" "View All" or "Search" options in the "Admin -> Appearance -> Menus -> Search" first. Commented Mar 29, 2012 at 22:12
  • i think once on "view all" you can search using your internal broweser search using the page name and those find it easily... i think it would be just as fast and really the same as searching using wordpress.. Commented Mar 30, 2012 at 2:35
  • Thanks I tried it and it is a very us full trick I must say. On the "View All" tab WordPress will show 50 pages in a group then you need to select "<< 1 2 3 etc..." navigation to see the next group of pages. I use the browser's search function to highlight the pages that I need. Commented Mar 30, 2012 at 15:22
0

I also needed this functionality, the answer is around line 330 in wp-admin/includes/nav-menu.php

Change:

'posts_per_page' => 10, 

to:

'posts_per_page' => 1000, 

or whatever you'd like. Note you can also change the number of items under the other tabs in this file.

This applies to version 3.4.2 of wordpress.

2
  • Then you would be stuck at this WP version, because you cannot upgrade anymore without losing the changes. Not a good idea. Commented Nov 8, 2012 at 16:59
  • Still, good enough for a temporary fix (just to get the menus established) if you're setting up nav for a site with hundreds of pages. The search functionality really doesn't work well and paginating through the 'View All' can take ages. Thanks John! Commented Feb 4, 2013 at 23:24
-1

In the newer Wordpress version 4.9.5, it is line '80' in nav-menu.php.

To change the number of Wordpress menu pages search results (Admin > Appearance > Menus > Search) from 10 results to more go to:

wp-admin > includes > nav-menus.php > line '80' > 'posts_per_page' => 10,
Change the 10 to some other number.

This assumes you have a way to actually edit nav-menu.php. Or can change the permissions if need be so that you can edit. And yes, it also assumes you will need to re-implement if there is a Wordpress upgrade. But once you have your menu configured, it may not even be necessary after that. A default of 10 search results, is downright silly in my opinion. Some sites have hundreds, even thousands of posts or pages.

2
  • It is bad practice to change the WordPress source directly as you will either lose changes when updating it, or be forced to avoid updating WordPress. Commented Jun 26, 2018 at 1:27
  • I understand... that's why I clearly stated: "it also assumes you will need to re-implement if there is a Wordpress upgrade". Commented Sep 24, 2018 at 15:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.