Support

Account

Home Forums Backend Issues (wp-admin) Update field not replacing it's content if post date is changed

Solved

Update field not replacing it's content if post date is changed

  • Hi, just wrote a code that adds 6 weeks to the post date, which is stored in another custom field. (trying to create a function that when that time in the future is there, the post category changes).

    However I couldnt help but notice that once the value is saved, and the post date is altered, the custom field doesn’t update.

    Is this a bug or am I missing something here ?

    function my_acf_update_value( $value, $post_id, $field  ) {
    	
    	// override value
      
        $date = get_the_time( '', $post->ID );
        $value = (get_the_time ('U', $post->ID) + 3628800); 
    
        // do something else to the $post object via the $post_id
    	
    	// return
        return $value;
        
    }
    
    add_filter('acf/update_value/name=event_end_date', 'my_acf_update_value', 10, 3);
  • Try setting your priority higher

    
    add_filter('acf/update_value/name=event_end_date', 'my_acf_update_value', 20, 3);
    

    Also, I’m not sure what format the value needs to be in. A date field does not store a Unix time stamp, so this might be incorrect. get_the_time ('U', $post->ID) + 3628800 You need to figure out the format of the value that ACF is passing your filter and then return the correctly formatted value.
    I would do this by temporarily adding

    
    echo $value;die;
    

    at the beginning of the function to figure out what I need to do.

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

You must be logged in to reply to this topic.