I like to set validation when both fields named species1 and species2 are no values.
I set below code on function.php. Now, validation always stops update however I set value on these field.
//ACF
function my_acf_validate_value( $valid, $value, $field, $input ){
if( !$valid ) {
return $valid;
}
$value_1 = $_POST['acf']['species1'];
$value_2 = $_POST['acf']['species2'];
if (empty($value_1) && empty($value_2)) {
$valid = 'Please complete at least one of the fields';
}
return $valid;
}
add_filter('acf/validate_value/name=species1', 'my_acf_validate_value', 10, 4);
add_filter('acf/validate_value/name=species2', 'my_acf_validate_value', 10, 4);
$valid
regardless of the conditions, but I don't see what$valid
is if theif()
condition isn't met. Add avar_dump( $valid );
beneathreturn $valid;
to see what it contains. My guess would benull
.