I've got a wordpress site using MAMP on localhost. Everything's running fine, right up until I try to modify the menu. The menu has about 34 items on it, mostly pages, with a few custom links (placeholders for pages I haven't made yet).

When I try to save the menu after modifying it (Adding another page, or a custom link), the menu fails to save correctly. I get a save successful error, but all custom links become first level menu items, the page I was trying to add becomes an empty custom link, and (heres the weird part) the page I was trying to add has its page layout metadata reset. Specifically, the page-top, page-bottom, and the sidebar settings all reset to their default settings. (Which means that suddenly theres a sidebar and a ton of padding, making the page look awful, along with a garbled menu).

I found a few other questions which seemed similiar, and I tried a few fixes, specificlly, adding these lines to mamps php.ini:

max_input_vars = 5000
max_execution_time = 600
memory_limit = 64M
max_input_time = 600

I can see these values reflected in phpMyAdmin's phpInfo.

This seems 100% caused by the server memory limit, but this seems like a really low number to cause it, and the fix provided for the memory limit does not seem to fix this issue.

I am able to fix the locations of the items using the menu editor, but once I try to add a new page to the menu, the existing custom links become top level, and the page shows up as a blank custom link.

I don't see anything unusual in my debug logs either, just the usual errors:

[28-Feb-2018 20:21:03 UTC] PHP Notice: wp_richedit_pre is deprecated since version 4.3.0! Use format_for_editor() instead. in /local/wp-includes/functions.php on line 3839 [28-Feb-2018 22:22:52 Europe/Berlin] PHP Fatal error: Call to undefined function luxe_get_meta() in /local/wp-content/themes/simpleflex/index.php on line 3

This however, does not fix my problem. I am able to modify the menu using the customizer, but its a poor fix for this issue. (Mostly because there are other staff members who might not remember which way to edit the menu & cause this issue).

  • If anyone has a suggestion on additional information, or tags to use, please let me know in the comments, Im primarily a salesforce developer & could very easily be missing something in this post. Commented Feb 28, 2018 at 21:30
  • When I created this local site, I imported some of the database items from production. The table for posts was created without a primary key, and when I went to add one, I was met with an error, and had to go into the database, and give non-zero ids to a bunch of menu items to get the field to have unique ids. I'm wondering if this screwed up some part of the wordpress menu process that I might not be familiar with. Commented Mar 6, 2018 at 14:35
  • Interesting write up here with a similar issue, I hope this helps you find a solution. wpbeginner.com/wp-tutorials/… Commented Mar 6, 2018 at 15:19

2 Answers 2


Obviously, this is non standard WP behaviour, so tons of things could be wrong, but there are some ways to track down the error. The most important thing, I think, is the fact that storing the menu through the customizer works. This means that the function which does the storing of single menu items wp_update_nav_menu_item is functioning correctly, because this function is called directly from the customizer.

The path from the menu page to this function is different, namely through the function wp_nav_menu_update_menu_items. Given that things only go wrong once you want to save the menu, something systematically screws up while executing this function, which is not very complex:

  1. Read the current menu as stored in the database
  2. Loop through all the items in the $_POST variable and call wp_update_nav_menu_item to store them one by one.
  3. Delete all menu items that were stored in the database but were not in $_POST, so presumably were removed by the user

Under 2 you see a double foreach loop involving multidimensional arrays, which explains why things can get out of hand memorywise (which is why you see the wp_defer_term_counting function at the beginning, to save some memory). My guess would be that memory problems leads to empty values of the $args variable passed to wp_update_nav_menu_item and hence faulty menu items. Since menu items are posts in the database a screwup could even lead to the metadata of a page (also a post type) being wiped when the ID of the linked page is passed in stead of the menu item ID, even though there is a test for that at the beginning of wp_update_nav_menu_item.

These days WP needs a 128 MB memory limit, so you should raise that. In my experience 64MB leads to unexpected results regularly.

If that's not possible or doesn't work, there's a workaround. There is a third function you can use to call wp_update_nav_menu_item: wp_save_nav_menu_items. This is an ajax-call that you can build into the menu page to save menu items one by one in stead of having to save the whole menu at once, thus evading memory issues. That would involve adding save buttons to every menu item and removing the general save button. There's a lenghty tutorial here. Not an ideal solution, but if you cannot solve the server issue it could help.

  • Opened up my customizer to find that a bunch of items had been corrupted, and were now showing blank custom links. Looks like my php settings had been reset too (this was due to updating the php version used with mamp). Going to try these steps again in order. Very sure this is the right answer. Commented Mar 14, 2018 at 13:57
  • Even the customizers broken now. Trying to drop some items under a parent menu item will occasionally result in them getting randomly reparented. Seems to be when the item is the last item under their parent. I've doubled all the limits in my post & this is still happening. Commented Mar 14, 2018 at 14:20
  • Bounty given for accurately summarizing my options & proving a solution beyond what is available via google. Commented Mar 14, 2018 at 14:52

I don't have any solution for your problem. At first I thought also on the php value for max_input_vars.

However you should debug about the save process, like the follow small example to get the array with all data from each menu item. This should helps you to unserstand, is the save process ok, is the problem before save on send post data or on the save process.

 * Plugin Name: .my Debug

add_action( 'wp_update_nav_menu', function( $menu_id, $menu_data ) {


    return $menu_id;
}, 10, 2 );

add_action( 'wp_update_nav_menu_item', function( $menu_id, $menu_item_id, $args ) {

    echo '<pre>'; var_dump($args); echo '</pre>';

    return $menu_id;
}, 10, 3 );

This two functions debug the menu name at first and after this you should get an output of each menu item, that you would save. You find the functions for this process in /wp-admin/includes/nav-menu.php

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.