Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm running WP 3.5.1 and I've a menu with about 100 items. When I add new items to the menu older ones disappear.

I'm not running Suhosin or similar stuff. What can be the cause?

Note: I'm on a dedicated server.

share|improve this question

1 Answer 1

up vote 12 down vote accepted

The following has worked for some users with similar problem:

Try to increase the value of the max_input_vars variable in php.ini. This variable was introduced in PHP version 5.3.9 and has the default value of 1000.

You can read more about it in the PHP documentation:

http://php.net/manual/en/info.configuration.php

max_input_vars  1000    PHP_INI_PERDIR  Available since PHP 5.3.9.

How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately). Use of this directive mitigates the possibility of denial of service attacks which use hash collisions.

You could try to increase it to 1500 or 2000.

Estimate:

Using the data below, we can try to estimate how many POST variables we are sending, given a certain number of menu items, when we press the Save Menu button

save

It seems to be:

"number of POST variables" = 11 * "number of menu items" + 9

which is equivalent to the line:

y=11x+9

Then we can build the following table:

table

In your case, we see that if you need to save 100 menu items, you need to send 1109 POST variables, so your max_input_vars must be at least 1109.

Similarly when we add items to the menu (via Ajax POST)

add

we get

"number of POST variables" = 10 * "number of menu items" + 3

which is the line:

y=10x+3

The corresponding data table is:

table

When we add 10 menu items, we send 103 POST variables.

Data:

Just to show you the amount of $_POST data when I save my menu with only 5 items:

Array
(
    [menu-name] => simple_menu
    [save_menu] => Save Menu
    [closedpostboxesnonce] => xxxxxxxxxx
    [meta-box-order-nonce] => xxxxxxxxxx
    [update-nav-menu-nonce] => xxxxxxxxxx
    [_wp_http_referer] => /dev/wp-admin/nav-menus.php
    [action] => update
    [menu] => 58
    [menu-item-title] => Array
        (
            [1135] => home
            [1131] => page1
            [1130] => page2
            [1132] => page3
            [1133] => page4
        )

    [menu-item-attr-title] => Array
        (
            [1135] => 
            [1131] => 
            [1130] => 
            [1132] => 
            [1133] => 
        )

    [menu-item-classes] => Array
        (
            [1135] => 
            [1131] => 
            [1130] => 
            [1132] => 
            [1133] => 
        )

    [menu-item-xfn] => Array
        (
            [1135] => 
            [1131] => 
            [1130] => 
            [1132] => 
            [1133] => 
        )

    [menu-item-description] => Array
        (
            [1135] => 
            [1131] => 
            [1130] => 
            [1132] => 
            [1133] => 
        )

    [menu-item-db-id] => Array
        (
            [1135] => 1135
            [1131] => 1131
            [1130] => 1130
            [1132] => 1132
            [1133] => 1133
        )

    [menu-item-object-id] => Array
        (
            [1135] => 477
            [1131] => 1020
            [1130] => 1028
            [1132] => 791
            [1133] => 603
        )

    [menu-item-object] => Array
        (
            [1135] => page
            [1131] => page
            [1130] => page
            [1132] => page
            [1133] => page
        )

    [menu-item-parent-id] => Array
        (
            [1135] => 0
            [1131] => 0
            [1130] => 1131
            [1132] => 1131
            [1133] => 0
        )

    [menu-item-position] => Array
        (
            [1135] => 1
            [1131] => 2
            [1130] => 3
            [1132] => 4
            [1133] => 5
        )

    [menu-item-type] => Array
        (
            [1135] => post_type
            [1131] => post_type
            [1130] => post_type
            [1132] => post_type
            [1133] => post_type
        )

    [menu-locations] => Array
        (
            [primary] => 0
        )

)

When I add 3 items to them menu, the POST data is:

Array
(
    [action] => add-menu-item
    [menu] => 58
    [menu-settings-column-nonce] => xxxxxxxxxx
    [menu-item] => Array
        (
            [-56] => Array
                (
                    [menu-item-object-id] => 1728
                    [menu-item-db-id] => 0
                    [menu-item-object] => page
                    [menu-item-parent-id] => 0
                    [menu-item-type] => post_type
                    [menu-item-title] => Page 1
                    [menu-item-url] => http://example.com/page1/
                    [menu-item-target] => 
                    [menu-item-classes] => 
                    [menu-item-xfn] => 
                )

            [-57] => Array
                (
                    [menu-item-object-id] => 1724
                    [menu-item-db-id] => 0
                    [menu-item-object] => page
                    [menu-item-parent-id] => 0
                    [menu-item-type] => post_type
                    [menu-item-title] => Page 3
                    [menu-item-url] => http://example.com/page2/
                    [menu-item-target] => 
                    [menu-item-classes] => 
                    [menu-item-xfn] => 
                )

            [-59] => Array
                (
                    [menu-item-object-id] => 1658
                    [menu-item-db-id] => 0
                    [menu-item-object] => page
                    [menu-item-parent-id] => 0
                    [menu-item-type] => post_type
                    [menu-item-title] => Page 3
                    [menu-item-url] => http://example.com/page3/
                    [menu-item-target] => 
                    [menu-item-classes] => 
                    [menu-item-xfn] => 
                )

        )

)
share|improve this answer
    
Hey thank you! I will try that @birgire! –  Herr K Apr 21 '13 at 5:03
2  
+1 great explanation, great detail. Perfect answer. –  kaiser Apr 24 '13 at 17:54
    
Update after 10 months, thank you!:) –  Herr K Feb 27 at 18:30
    
Is it worth trying this if your menu items for all menus are randomly being deleted on their own would you say? –  zigojacko May 28 at 12:31
    
Setting our max_input_vars to 2000 didn't resolve the issue for us and we only have about 15 menu items. –  zigojacko Jun 12 at 11:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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