Support » Fixing WordPress » Fix nav-menu.php to display more items

  • Resolved pawanahluwalia



    I am trying to add a menu item. I have about 700+ pages. The page does not show up when I select Admin -> Appearance -> Menus. I have tried both the ‘View All’ option and the ‘Search’ option. The only way to add the page is by using the ‘Custom Links’ option, rather than selecting the page directly.

    There seems to be a built in limit of displaying about 500 pages in the ‘View All’ option.

    This seems to be controlled by wp-admin > includes > nav-menu.php.

    How can I override this in my own functions file.

    How can I also change the number of items shown under the ‘Most Recent’ and ‘Search’ tabs without changing nav-menu.php directly.

    I would be grateful for any help in finding a solution.


Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi @pawanahluwalia

    I created 700 pages in my local test environment and was able to see them all paginated under “View All”.

    Screen Shot 2021 07 20 at 11 21 22

    Are you seeing something different?

    Alternatively, do you know which part of nav-menu.php you’d like to change and maybe I can help you work out how to do it with a filter?

    Thread Starter pawanahluwalia


    That’s really strange, because all I see is this:!Aisv2-jkZTyIjt1Hvc4zeD3jFEKf5w?e=2ibJUl

    Mine won’t show more than 10 pages of 50 items and the ‘Search’ can’t find all of the pages.

    ‘View All’ seems to controlled by line 646 onwards.

    I’ve tried changing ‘$per_page = 50;’ on line 701, but it didn’t make any difference.

    Any filter I can apply would be amazing. Thanks!

    Are the pages that you expect to see published? Only published pages are shown in this selector.

    If modifying wp-admin/includes/nav-menu.php doesn’t fix the problem then I don’t think a filter will help.

    Thread Starter pawanahluwalia


    Thank you. You just hit the nail on the head.

    The issue is that many of my pages are set as ‘Private’. That’s why I couldn’t see all of the pages under ‘View All’.

    I did a test and set all pages to ‘Published’ – then I could see 16 pages under ‘View All’. So I now understand the issue.

    Thanks for helping me understand.

    However, are there filters I can use to increase the number of results shown under ‘Most Recent’ and ‘Search’ rather than hard coding them in nav-menu.php. The number of ‘Most Recent’ seems to be set on line 536. I’m not sure which line sets the ‘Search’ results.

    Looking at line 536, it seems that using nav_menu_items_{$post_type_name}_recent should do the trick. It’s a little tricky but essentially you could re-run the WP_Query inside that filter. Note that I haven’t tested this code.

    	function( $most_recent, $args, $box, $recent_args ) {
    		$recent_args = array_merge(
    				'posts_per_page' => 50, // Changing the number of posts
    		$get_posts = new WP_Query;
    		$most_recent = $get_posts->query( $recent_args );
    		return $most_recent;

    Thread Starter pawanahluwalia


    Thank you that works.

    Can you give me something similar for the ‘Search’ tab to increase the number of results there also. This appears to be set in line 82.

    Unfortunately there’s no filter we can use to increase the number of results in ‘Search’.

    Thread Starter pawanahluwalia


    That’s a shame. Line 82 is definitely the one that changes this.

    Is there no way to override the posts_per_page parameter?

    If not, then I’ll just change it manually each time there is a WordPress update, which is not ideal.

    If you’d like you could open a ticket here to add a filter for this. It sounds like a reasonable enhancement request to me. (Bonus points if you add a patch which implements the new filter 🙂 )

    You maybe could look at using at a WP_Query filter or a wp_ajax_{$action} filter but it would be pretty gnarly and probably more work to maintain than just patching core.

    Thread Starter pawanahluwalia


    I have submitted a ticket as you suggested.

    Thanks for your help on this. I really appreciate it!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Fix nav-menu.php to display more items’ is closed to new replies.