Support

Account

Home Forums Feature Requests Date Time Picker should optionally save timestamp Reply To: Date Time Picker should optionally save timestamp

  • @hatsumatsu ‘s solution works great, except I can’t seem to be able to make it work with a date field assigned to a custom taxonomy. I’m using it for a date picker like this:

    /**
     * Convert values of ACF core date pickers from Ymd 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_wp_date( $value, $post_id, $field  ) {
        if( $value ) {
            $value = strtotime( $value );
        }
    
        return $value;    
    }
    
    add_filter( 'acf/update_value/type=date_picker', 'acf_save_as_wp_date', 10, 3 );
    
    /**
     * Convert values of ACF core date pickers from timestamp to Ymd
     * @param  string $value   unmodified value
     * @param  int    $post_id post ID
     * @param  object $field   field object
     * @return string          modified value
     */
    function acf_load_as_acf_date( $value, $post_id, $field  ) {
        if( $value ) {
            $value = date( 'Ymd', $value );
        }
    
        return $value;    
    }
    
    add_filter( 'acf/load_value/type=date_picker', 'acf_load_as_acf_date', 10, 3 );

    Tried adding the name of taxonomy, like $value = strtotime( $value, 'event_dates' ); and $value = date( 'Ymd', $value, 'event_dates' ); as well, but I don’t know if that’s at all correct way of doing it.