admin管理员组文章数量:1402138
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
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
Share Improve this question asked Mar 28, 2012 at 15:40 TonyTony 611 silver badge2 bronze badges 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? – Sagive 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/appearance-menus-search.png ) – Tony Commented Mar 29, 2012 at 13:51
5 Answers
Reset to default 10No 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/raw/jRkJYAzE )
add_action( 'pre_get_posts', 'myFilter1', 10, 2 );
function myFilter1( $q ) {
// example of $q properties: https://pastebin/raw/YK1uaE0M
if(isset($_POST['action']) && $_POST['action']=="menu-quick-search" && isset($_POST['menu-settings-column-nonce'])){
// other parameters for more refinement: https://pastebin/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.
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:
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.
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' );
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.
本文标签: Increase search results for Admin gt Appearance gt Menus gt Search (default is 10)
版权声明:本文标题:Increase search results for Admin -> Appearance -> Menus -> Search (default is 10) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744346110a2601769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论