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, 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
$_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
How to check
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:
How to increase
There are several ways to increase the value of
max_input_vars. You can edit
.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.
max_input_vars value in
php.ini file and find the line containing
max_input_vars and change the value as follows:
max_input_vars = 10000
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:
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.
max_input_vars value by
If you do not have access or are not be able to edit the
php.ini file, you can increase the value of
.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
max_input_vars value by PHP
If the above does not work, try adding the following code to the
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
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
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.
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.