Support

Account

Home Forums ACF PRO Must update post twice to get values passed Reply To: Must update post twice to get values passed

  • That’s what’s in my reply above.

    The problem is that the update_value fires before that value is saved to the database.

    This means that when you do get_field to get the value you are getting the value it was from the previous update. If it’s a new post then you get nothing, if you change the date you will get the previous date.

    The hook passes the new value as $value so you should be using that for the value to update the title

    
    function my_acf_update_value( $value, $post_id, $field ) {
    	
            // ** change this line
    	$date = strtotime($value);
    
    	$formatted_date = date('d F Y', $date);
                    $new_title = $formatted_date;
    
    	// update post
    	
    	$my_post = array(
    	'ID'           => $post_id,
    	'post_title' => $new_title,
    	'post_type' => 'usa',
    	'post_name' => $new_slug
    	);
    	
    	// Update the post into the database
    	wp_update_post( $my_post );
    	return $value;
    	}