Home › Forums › Backend Issues (wp-admin) › Bypass required fields
Hello,
through the development of the new website I would like to turn off required validation for all fields. I was able to turn off the required flag when the field is printed:
add_filter( 'acf/get_fields', 'turn_of_require' );
function turn_of_require( $fields ) {
foreach ( $fields as &$field ) {
$field['required'] = 0;
}
return $fields;
}
This removes the red star, etc. Unfortunately, the validation script does not get the information about the change and it thinks that fields are still required.
I know that I could turn off all validation rules via action validate_save_post
, but it turns off all rules. I would like to turn off only the required validation.
Is there any possibility how to do that?
You need to edit the field group and edit the field to turn off required.
Thanks for your respond. I know about this possibility.
My problem is somehow different. Those fields are provided by another plugin which I dont want to change because any update would restore the require flag.
So I am searching for some method which helps me to turn of required flag without changing the register method of the field.
You will need to use the acf/load_field hook for each field.
Hello, a bit of an old post, but I am facing the same issue. I am running the function using ‘load_field’ and although the field is set as ‘not required’ and this is reflected on the output html, after submitting the form I can still see an error.
function acf_classified_date_required_change( $field ) {
$field['required'] = false;
return $field;
}
add_filter('acf/load_field/name=classified_date', 'acf_classified_date_required_change');
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.