[ad_1]
in ev_date_end, ev_date_start date time in timestamp format like: 1701601399
Your code seems to be incorrect. If the meta values are supposed to be timestamps, you are not supposed to use strtotime() and after adding an hour to the event start timestamp, you are again setting the same meta, i.e., ev_date_start instead of ev_date_end.
Haven’t tested, but you need something like this:
<?php
function validate_fb_post_meta($meta_id, $post_id, $meta_key, $meta_value) {
if ($meta_key !== 'ev_date_end') {
return; // Not our meta key
}
if (get_post_type($post_id) !== 'event') {
return; // Not our post type
}
if (empty($meta_value)) {
$start_date = get_post_meta($post_id, 'ev_date_start', true);
if (empty($start_date)) {
// Add your logic if even ev_date_start is empty
} else {
$start_ts = filter_var($start_date, FILTER_VALIDATE_INT);
if ($start_ts === false) {
// Add your logic if ev_date_start value is not a valid integer. TS are integer values
} else {
$end_date = $start_date + 3600;
update_post_meta($post_id, 'ev_date_end', strtotime($end_date));
}
}
}
}
add_action('added_post_meta', 'validate_fb_post_meta', 10, 4);
thanks for quick help…..
I use particaly your constructor and I not correct convert time to TS. This right:
if (empty($meta_value)) {
$start_date = get_post_meta($post_id, 'ev_date_start', true);
$end_date = strtotime('+ 1 hour', $start_date);
update_post_meta($post_id, 'ev_date_end', $end_date);now works, thanks.
