I created custom fields with ACF to define a new date for my post on wordpress.
I then created this function that updates the date with my custom field and works when I update a post.
// Save ACF custom field to date-time post
function my_acf_save_post( $post_id ) {
$acfDate = get_field('data_time_post', $post_id);
//Test if you receive the data field correctly:
//echo $acfDate;
//exit (-1);
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_date'] = $acfDate;
wp_update_post ( $my_post );
}
add_action('acf/save_post', 'my_acf_save_post', 20);
But it doesn’t work when I create a new post, only whn update
I think the problem is this function:
wp_update_post
Thank you all.