[Résolu] Populate custom field with number of days calculated from two date fields
Ce fil est résolu. Voici une description du problème et la solution proposée.
Problem:
I have 3 custom fields: wpcf-start-date, wpcf-end-date and wpcf-total-days. When a form is submitted I'd like wpcf-total-days to be populated with the number of days from the other two fields.
I have 3 custom fields: wpcf-start-date, wpcf-end-date and wpcf-total-days. When a form is submitted I'd like wpcf-total-days to be populated with the number of days from the other two fields. I've created this hook but the number returned is '1'. Not sure where it's not quite right! Can you help please?
add_action('cred_submit_complete', 'after_save_data_action_111',10,2);
function after_save_data_action_111($post_id, $form_data) {
// if a specific form
if ($form_data['id']==111) {
$date1 = get_post_meta($post->ID, 'wpcf-start-date', true);
$date2 = get_post_meta($post->ID, 'wpcf-end-date', true);
$secondsdiff = $date1 - $date2 - 86400;
$totaldays = ( $secondsdiff / ( 60*60*24*-1) );
update_post_meta($post_id, 'wpcf-total-days', $totaldays);
}
}