Working on a function that uses three fields to automatically form a Post Title.
However, I’m noticing that on first save, it only records the $client.
When I hit Update Post, the $client, $location, and $service all work. At that point the Title, and Slug update with all three variables correctly.
Should my hooks be one after the other like that? Not sure what I’m missing here…
function aesthetics_acf_title( $value, $post_id, $field ) {
$client = get_field( 'client', $post_id );
$location = get_field( 'location', $post_id );
$location = get_term( $location, $taxonomy );
$service = get_field( 'case_study_service', $post_id );
$title = $client->post_title . '-' . $location->name . '-' . $service->post_title;
$slug = sanitize_title( $title );
$postdata = array(
'ID' => $post_id,
'post_title' => $title,
'post_type' => 'case-study',
'post_name' => $slug,
);
wp_update_post( $postdata );
return $value;
}
add_filter( 'acf/update_value/name=client', 'aesthetics_acf_title', 10, 3 );
add_filter( 'acf/update_value/name=location', 'aesthetics_acf_title', 10, 3 );
add_filter( 'acf/update_value/name=service', 'aesthetics_acf_title', 10, 3 );