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 🙂