WordPress custom fields not saving? PHP’s max_input_vars may be to blame.

On two occasions recently I have run into a problem where WordPress custom fields were disappearing after a post was edited. The first time I noticed this odd behaviour was on a site using the Advanced Custom Fields Repeater add-on for an image gallery. Each gallery item contained an image field along with several meta data fields, and once the gallery grew significantly large new items stopped being created. All of the existing gallery items would save successfully, but newly created fields would disappear when the post was updated.

The second time I encountered disappearing data was on a WooCommerce installation using the Per Product Shipping module. This module requires shipping costs to be entered individually for each country (why, WHY?) and as a consequence each product had a large number of custom fields. Surprisingly it wasn’t the shipping costs that were disappearing, but the product attributes – size, colour and so forth. This had disastrous effects, since when the attributes disappeared the linked product variations were removed too, along with the product prices.

In both cases data would only disappear on the production web server. When I worked on the sites locally custom fields would save as expected, so I was fairly certain that the server configuration was to blame. No errors were being displayed within WordPress or in my server logs so I initially focussed on MySQL, since the bug seemed to stem from a failure to write to the WordPress database. That line of enquiry proved fruitless, but thankfully I came across a thread on the Advanced Custom Fields forum which mentioned PHP’s max_input_vars setting as a potential culprit.

max_input_vars was introduced in PHP 5.3.9, and limits the number of $_POST, $_GET or $_COOKIE input variables that PHP will accept. Further variables are truncated from the request. The default value for max_input_vars is 1000, which means that if your form has has more than 1000 inputs, any additional values will be lost. Since each custom field is an input in the WordPress editor, plugins like Advanced Custom Fields Repeater and Per-Product Shipping make it possible to exceed the 1000 input limit.

You can increase max_input_vars in your php.ini file:

max_input_vars = 3000

or in an .htaccess document:

php_value max_input_vars 3000

After doing that you should find that you can once again save a large number of custom fields.

15 thoughts on “WordPress custom fields not saving? PHP’s max_input_vars may be to blame.

  1. Kat says:

    You have saved the day! Thanks so much for this, Jonathan.

  2. DBS says:

    I’m having the same trouble. But when I change the php.ini file, it doesn’t accept the changes (I’m using WooCommerce and it’s a product with too many variations). So I tried to change the .htaccess file and mod_security doesn’t allow that change. Any ideas?

  3. Jonathan says:

    @DBS If you can’t change max_input_vars via .htaccess yourself, your web host may be able to do it for you.

  4. Luke says:

    Awesome! Thank you so much!

  5. Chris Howard says:

    Ah!! Thank you. I been tearing my hair out on this one!

    However… it’s all well an good on my site, but doesn’t actually resolve the issue of the 1000 variables.

    How can I reduce the number or variables? Will more arrays in my plugins help?


  6. Jonathan says:

    @Chris Howard The options for reducing the number of post variables depends on which plugin is producing them. In my case it wasn’t practical to reduce the number of post vars.

  7. Chris Howard says:

    Thanks, Jonathon. Have learned over the last few days just how widespread this frustration is. Which is good when you have to explain to customers it’s not a bug in your plugin! In the end, all I’ve been able to do is put a message in my plugin that shows when they enable features that might take it over the limit.

    Thanks again.

  8. JOKERz says:

    Thanks though!!
    Work like a charm

  9. The tip of the day! Thanks!

  10. Hey, thank you for the tip!
    After I have changed the max_input_var to 3000 I was able to add more fields but now my database crashes. I keep on getting an database error.

    Do you know what might be causing this?

  11. Gustavo Rabelo says:

    I`am having the same problem and my settings in php.ini are as follows:

    suhosin.post.max_array_index_length = 256
    suhosin.post.max_totalname_length = 65535
    suhosin.post.max_vars = 5000
    suhosin.request.max_array_index_length = 256
    suhosin.request.max_totalname_length = 65535
    suhosin.request.max_vars = 5000

    max_input_vars = 5000
    max_execution_time = 300
    max_input_time = 600
    memory_limit = 256M

    Can you help me to solve this issue?

    Best Regards

  12. Jonny Jordan says:

    I ended up solving it a different way and I wrote a short tutorial about it How to Increase the Menu Items Limit In WordPress

  13. team php says:

    Thank you its working…………!!!!!!!!!

  14. Jamal says:


    How? Because no .htaccess

  15. thank you, it’s work for me

Comments are closed.