Support

Account

Forum Replies Created

  • Okay, so it’s about taking the filter / actions approach. This way converting the field value when saving a post is not enough, you also have to convert the value back when the field is loaded by ACF otherwise the date picker UI doesn’t work:

    This works for me:

    
    /**
     * Convert values of ACF core date time pickers from Y-m-d H:i:s to timestamp
     * @param  string $value   unmodified value
     * @param  int    $post_id post ID
     * @param  object $field   field object
     * @return string          modified value
     */
    function acf_save_as_timestamp( $value, $post_id, $field  ) {
        if( $value ) {
            $value = strtotime( $value );
        }
    
        return $value;    
    }
    
    add_filter( 'acf/update_value/type=date_time_picker', 'acf_save_as_timestamp', 10, 3 );
    
    /**
     * Convert values of ACF core date time pickers from timestamp to Y-m-d H:i:s
     * @param  string $value   unmodified value
     * @param  int    $post_id post ID
     * @param  object $field   field object
     * @return string          modified value
     */
    function acf_load_as_timestamp( $value, $post_id, $field  ) {
        if( $value ) {
            $value = date( 'Y-m-d H:i:s', $value );
        }
    
        return $value;    
    }
    
    add_filter( 'acf/load_value/type=date_time_picker', 'acf_load_as_timestamp', 10, 3 );
    
  • +1 for an option to save as timestamp, seems way more flexible to me.

    (Can’t view James’ reply since it’s marked private)

    I have a site with complex timestamp-based queries using the Date and Time Picker Addon, but after the latest ACF update this is broken in combination with the newly introduced date and time picker in ACF core. So I’m basically left with either coming up with a hook to convert the data into timestamp everytim a date is saved (seems rather hacky to me) or rewriting all of my queries? o_o

    An option to save data as timestamp would be greatly appreciated!

  • You’re absolutely right, the JS in question was added by the Validated Field addon. Sorry for not checking before posting.

    I started a thread on the wordpress.org in case someone has these problems, too.

Viewing 3 posts - 1 through 3 (of 3 total)

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.