Support

Account

Home Forums General Issues Hook/Filter to edit the timestamp after user has selected a date and time Reply To: Hook/Filter to edit the timestamp after user has selected a date and time

  • Update: So I have found this http://www.advancedcustomfields.com/resources/acfsave_post/.

    I am hooking into it, but the date isn’t actually being written to the database. Not sure why not. Here is my code:

    function updateSeminarTime( $post_id ) {
    
        // bail early if no ACF data
        if( empty($_POST['acf']) ) {
    
            return;
    
        }
    
        // array of field values
        //$fields = $_POST['acf'];
    
        // specific field value
        $post = get_post( $post_id );
        $expertId =  $post->post_author;
        $userTimeZone = getTimeZone($expertId);
        $userTimeZoneOffset = get_timezone_offset($userTimeZone,'UTC');
        $seminarDate = $_POST['acf']['seminar_date'];
        $seminarDate = strtotime($seminarDate);
        $seminarDate = $seminarDate + $userTimeZoneOffset;
        $seminarDate = date('m/d/y h:mm tt',$seminarDate);
        $_POST['acf']['seminar_date'] = $seminarDate;
    
    }
    
    // run before ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'updateSeminarTime', 1);

    I’m wondering if I am writing the format wrong. BTW I have tried with date() and formatting it to a string and also just as a UNIX timestamp.