How to set custom post type field as post title to avoid ‘Auto Draft’

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);
«
»
ACF (3)
Admin Column (4)
Breadcrumbs (2)
CSS (6)
Custom post types (4)
Custom Taxonomies (3)
Customizer (4)
Hooks & Filters (3)
Jquery (9)
LAMP (10)
Login (5)
Meta boxes (6)
Multisite (2)
My Code (1)
Open Graph Meta Tags (1)
Redirects (2)
SEO (4)
Theme Building (5)
Title Tags (2)
Typography (3)
Uncategorised (54)
User Roles & Capabilities (2)
White labeling (9)
Working with Images (11)
Working with videos (2)
WP Database (1)