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.
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:
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:
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.
Not only the number of custom fields affected by max_input_vars
, but all the activities related to form, submit are also 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!
Thank You
And if it still doesn't save?
Following text in a WYSIWYG field
We aim not only to increase the children's self confidence but to help them discover how fun learning English can be.
We do this by working with an international team of young people who run three camps for a total of 240 children, after 3 weeks training.
Each year, in December to January, we recruit 5 or 6 native English speaking volunteers who should be undergraduates or recent graduates of British universities, and 10 to 12 Hong Kong undergraduates majoring in English who are recruited directly from their universities. The two groups work in teams of 3.
The international volunteers are provided with pleasant accommodation at the Chinese YMCA Youth camp in Wu Kai Sha and we cover local transport costs and part of the food costs.
Saving just hangs
Latest WordPress
WOuld appreciate your help as I trying to resolve this. I suspect it is something to do with the environment as I have used ACF and Pods plugins and still no luck.
Thanks