Open Uatschitchun opened 2 years ago
ACF provides filters for this, so I tried to add a check to pages/form-veranstaltungen.php like:
function my_acf_validate_save_post( $valid, $post_id, $field ) {
// Check if start time and end time fields exist
if ( isset( $_POST['acf'][ 'field_1234567890abc' ] ) && isset( $_POST['acf'][ 'field_0987654321xyz' ] ) ) {
// Get start time and end time values from $_POST
$start_time = $_POST['acf'][ 'field_1234567890abc' ];
$end_time = $_POST['acf'][ 'field_0987654321xyz' ];
// Check if end time is smaller than start time
if ( $end_time < $start_time ) {
$valid = 'End time cannot be smaller than start time.';
}
}
// Return validation result
return $valid;
}
add_filter( 'acf/validate_save_post', 'my_acf_validate_save_post', 10, 3 );
or
function my_acf_validate_post( $valid, $post_id, $field ) {
$start_time = strtotime(get_field('start_time'));
$end_time = strtotime(get_field('end_time'));
if ( $end_time <= $start_time ) {
$valid = __('End time must be greater than start time', 'my_textdomain');
}
return $valid;
}
add_filter('acf/validate_post', 'my_acf_validate_post', 10, 3);
But couldn't get it to work as those seem to interfere with function cpt_save_worker
in functions.php
.
Getting undefined variable $time
and others in log and check isn't working.
There's a check in
download_calendar.php
:in
single_veranstaltungen.php
there isn't.