I’ve been playing with this issue and found a solution that works for me by compiling a few solutions I found.
add_filter('acf/validate_value/name=date_time_end', 'validate_end_date_func', 10, 4);
function validate_end_date_func($valid, $value, $field, $input) {
if (!$valid) {
return $valid;
}
$start_key = 'field_5f46d8cef3f0a';
$end_key = 'field_5f46d8eaf3f0b';
$start_value = $_POST['acf'][$start_key];
$start_value = new DateTime($start_value);
$end_value = $_POST['acf'][$end_key];
$end_value = new DateTime($end_value);
if ($end_value <= $start_value) {
$valid = 'The end date must come after the start date for this event.';
}
return $valid;
}
Like noted above:
* For the $start_key
and $end_key
You can get key of ACF field from screen option and then selecting field keys.
* In line 1 where name=date_time_end
set date_time_end
to your field name.