I then tried to also apply this function to 3 other forms, and modified it like this :
// Remplacer la date de publication du post lors de la saisie dans le cred form
add_action('cred_save_data', 'always_prefix_data_action',10,2);
function always_prefix_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==1754 || 2361 || 2405 || 2429)
{
//get post field value. This returns a TimeStamp if this is a Types Date Field
$timestamp = get_post_meta($post_id, 'wpcf-date-de-la-depeche', true);
$custom_date = gmdate("Y-m-d g:i:s", $timestamp);//convert timestamp to something like 2017-03-09 10:32:01 (Y/m/d g:i:s) for output and storage in the Database.
// Update post post_date (publication date) with this date
// Create $post_id object
$my_post = array(
'ID' => $post_id,
'post_date' => $custom_date,
);
// Update the post into the database
wp_update_post( $my_post );
}
}
But now I noticed it's causing an AJAX bug as described here https://toolset.com/forums/topic/ajax-error-when-submitting-form/, where Noman noticed the bug is solved when the function is limited to only one form. So I understand the bug comes from this part of the code :
// if a specific form
if ($form_data['id']==1754 || 2361 || 2405 || 2429)