I have a custom post type called artists, I combine the artist acf field of first_name and last_name and set that as the title.
// Auto-populate artist post type title with ACF first name last name.
function nd_update_postdata( $value, $post_id, $field ) {
// If this isn't an 'artists' post type, don't update it.
if ( get_post_type( $post_id ) == 'artists' ) {
$first_name = get_field('first_name', $post_id);
$last_name = get_field('last_name', $post_id);
$title = $first_name . ' ' . $last_name;
$slug = sanitize_title( $title );
$postdata = array(
'ID' => $post_id,
'post_title' => $title,
'post_type' => 'artists',
'post_name' => $slug
);
wp_update_post( $postdata, true );
return $value;
}
}
add_filter('acf/update_value/name=first_name', 'nd_update_postdata',
10, 3);
add_filter('acf/update_value/name=last_name', 'nd_update_postdata', 10,
3);
https://stackoverflow.com/questions/38857164/how-to-set-custom-post-type-field-as-post-title-to-avoid-auto-draft/50095929#50095929
Generate WordPress Post Tittle from ACF Fields
https://stackoverflow.com/questions/71565994/generate-wordpress-post-tittle-from-acf-fields
//Create new title based on ACF Fields
function update_contacts_title( $value, $post_id, $field ) {
$first_name = get_field('first_name', $post_id). ' ' . $value;
$last_name = get_field('last_name', $post_id). ' ' . $value;
//$title = $first_name .' - '. $last_name;
$title = $first_name;
$slug = sanitize_title( $title );
$postdata = array(
'ID' => $post_id,
'post_title' => $title,
'post_type' => 'contacts',
'post_name' => $slug
);
wp_update_post( $postdata );
return $value;
}
add_filter('acf/update_value/name=first_name', 'update_contacts_title', 10, 3);
//add_filter('acf/update_value/name=last_name', 'update_contacts_title', 10, 3);