Custom fields help customers enter data easily. They are used a lot in WordPress, especially for non-blog websites. Custom fields provide a convenient way to store data for not only logical processing (such as product price), but also for presentation purpose (such as landing pages).

However, there is a problem when using too many custom fields for a post – the custom fields might not be saved properly. For example, you use custom fields to create a landing page, which has multiple sections and each section has a lot of customization options. Then the number of custom fields is very large, up to thousands. And when you update the post, you might see some fields are not saved.

This is a fairly common problem. That’s not an error. No errors are saved. That’s just how PHP works with the max_input_vars directive.

This problem happens quite often if you use our Meta Box Group extension to include a lot of sub-fields. The extension allows you group fields into a repeatable groups, which makes them look more organized. Although, the number of inputs is still large and causes the problem.

What is max_input_vars?

max_input_vars, introduced in PHP 5.3.9, is an attempt for PHP to solve some security issues and when set, it limits your number of inputs (thus, custom fields) submitted in $_POST,$_GET or $_COOKIE. When the form you submitted has a larger number of inputs than the number set in max_input_vars then further input variables are truncated from the request.

The default value for max_input_vars is 1000, which means that if your form has more than 1000 inputs, any additional values will be lost.

If you find that your custom fields are not saved when submitted, this is likely to be the cause. In this case, you have to increase the value of max_input_vars.

How to check max_input_vars value?

Before increasing max_input_vars value, you need to know what the current value is. To do that, create a phpinfo.php with the following content and upload it to your host:

<!--?php phpinfo (); ?-->

And open it on your browser http://yourdomain.com/phpinfo.php, you will see the value of max_input_vars as below:

max_input_vars value

How to increase max_input_vars value?

There are several ways to increase the value of max_input_vars. You can edit php.ini, .htaccess or use PHP. Before going into the details, it’s worth noting that WordPress also has many default fields for posts such as post title, post content, publish date, categories, and tags. They can be up to tens or hundreds (if you have many categories). Thus, the value of max_input_vars should be greater than the total number of WordPress fields and your custom fields.

Increase max_input_vars value in php.ini

Open the php.ini file and find the line containing max_input_vars and change the value as follows:

max_input_vars = 10000

Normally, the php.ini file is located in /etc/php7.1/apache2/php.ini. However, if you do not know where php.ini is, open the file phpinfo.php (created in the previous step) and find the path to the php.ini file as below:

php.ini location

Some hosts put the php.ini file in your public_html directory. If that’s the case then that’s the php.ini file you need.

Increase max_input_vars value by .htaccess

If you do not have access or are not be able to edit the php.ini file, you can increase the value of max_input_vars with .htaccess. Open the .htaccess file at your root directory (usually public_html) and add the following line:

php_value max_input_vars 10000

If you do not have the .htaccess file, create it. Or visit the WordPress Dashboard → Settings → Permalink, choose a different permalink structure than the default and click Save button. WordPress will automatically generate the .htaccess file.

Increase max_input_vars value by PHP

If the above does not work, try adding the following code to the wp-config.php file:

ini_set('max_input_vars', 10000);

After increasing the value of max_input_vars, check if the new value is working (see how to check the value of max_input_vars above). In case that all three methods are not working, contact your host provider and ask for support.

Some other issues related to max_input_vars

Not only the number of custom fields affected by max_input_vars, all the activities related to form, submit are affected. So, if you use a form plugin, avoid creating too long forms. It is not only good for user experience but also avoiding potential problems with max_input_vars.

There is also another part of WordPress what is affected by max_input_vars – the menu. If you create a menu with too many items, then it is possible that the number of inputs will exceed the value of max_input_vars. Note that for each menu item, WordPress has a lot of inputs, such as title, description, class and relation. So, keep the number of menu items small.

Conclusion

Reduce the number of custom fields to make your edit screen cleaner. In case the number of your custom fields is too large, use the methods above to increase the value of max_input_vars to ensure they are saved properly. And also don’t forget the forms or menus in WordPress!


Also published on Medium.

1 thought on “WordPress custom fields not saving? Increase max_input_vars!

Leave a Reply