Is it possible to set the “publish date” of my custom posts with a ACF datepicker field?
My acf date picker field (startdate) is within a acf repeater field (courseinfo).
Tried the following code, but didn’t work out (after publishing, the post date was set to january 1970).
// Save ACF custom field to date-time post
function my_acf_save_post( $post_id ) {
$acfDate = get_post_meta($post_id, 'courseinfo_0_startdate', true);
$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);
Someone can help me out?
The ACF date picker field saves values to the database in “Ymd” format. This is not a correct date time format for use with the ACF post date field. You need to get the value saved by ACF using acf functions and/or convert the value returned to a date/time value in the format “Y-m-d H:i:s”.