The acf/update_value
filter won’t work as it’s meant for modifying the acf value and not the post it’s associated with. Try using the acf/save_post action instead. Here’s a simplified example of how I’d normally set the post title from first and last name fields in acf.
add_action( 'acf/save_post', 'biwp_set_title_from_first_last_name', 20 );
function biwp_set_title_from_first_last_name( $post_id ) {
$post_type = get_post_type( $post_id );
if ( 'contributor' == $post_type ) {
$first_name = get_field( 'biwp_first_name', $post_id );
$last_name = get_field( 'biwp_last_name', $post_id );
$title = $first_name . ' ' . $last_name;
$data = array(
'ID' => $post_id,
'post_title' => $title,
'post_name' => sanitize_title( $title ),
);
wp_update_post( $data );
}
}
Note the priority of 20 used in the action. A priority of less than 10 will hook into the acf/save_post
action before ACF has saved the $_POST data. While a priority greater than 10 will hook into the acf/save_post
action after ACF has saved the $_POST data. I’m using 20 so I can access the acf data that’s been saved.
Looking at the docs, Version 5.6.0 of acf has just added a parameter called $values which is an array containing the field values. You could use this to get the acf values directly instead of using get_field
.