Support

Account

Home Forums General Issues Update_field with term fields

Unread

Update_field with term fields

  • Hi,

    I have a custom taxonomy ‘dates’ and a date picker field added to all terms in that (location is set to Taxonomy -> Dates). I’m trying to convert the stored date into a timestamp. I found a great method for converting all date picker fields and it works great for fields that are attached to custom posts, but it doesn’t work for term fields. So I’ve been trying to figure out how to edit the update_field and load_value functions to work with this.
    This is always loading the field as August 25 1971 after saving it correctly.

    function save_as_wp_date( $value, $term_id, $field ) {
    	
    	if( $value ) {
    	$value = strtotime( $value );
    		 }
    
        return $value;    
    }
    add_filter('acf/update_value/type=date_picker', 'save_as_wp_date', 10, 3);
    
    function load_as_acf_date( $value, $term_id, $field ) {
     	
    	if( $value ) {
            $value = date( 'Ymd', $value );
        }
    
        return $value;    
    }
    
    add_filter( 'acf/load_value/type=date_picker', 'load_as_acf_date', 10, 3 );

    What am I doing wrong with this? Any help would be welcome, thanks

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.