Home › Forums › Backend Issues (wp-admin) › Date Time Picker and Post Loop › Reply To: Date Time Picker and Post Loop
Hi @poorpaddy
The old date-time add-on uses a timestamp to save the data in the database. If you don’t have a lot of posts, I suggest you re-save the old posts instead. This will make sure that it’s compatible with WordPress and ACF in the future.
If you don’t want to change the old data, then you can always convert the new date-time value to a timestamp instead. I believe you can do it by using this code:
function my_acf_save_post( $post_id ) {
// Set the date time field name
// change with the field key if it doesn't work
$date_time_field_name = 'event_start_date';
// get the saved date time value
$datetime = get_field($date_time_field_name, $post_id, false);
// if it exists
if( $datetime ){
// convert it to timestamp
$datetime_timestamp = strtotime($datetime);
// Update the value in the database
update_field( $date_time_field_name, $datetime_timestamp, $post_id );
}
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
Don’t forget to re-save the newly created post to convert the date-time value.
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.