'ACF Form Update duplicates post

i’m having a small issue.

Using a CPT, where no title is available, so i’m using the following code to make the title out of 2 ACF fields (first name / last name).

What is happening is that instead of updating, it’s making a new post with the new information. When i disable the script, everything works as intended.

Is there something that I could add to this script so that post update with forms work correctly?

function doctors_title_updater( $post_id )

{
    
    if ( get_post_type( $post_id ) == 'doctors' ) {

        $my_post = array();
        $my_post['ID'] = $post_id;
        $my_post['post_title'] = get_field( 'doctors_lname', $post_id ) . substr(get_field( 'doctors_fname', $post_id ), 0, 30) ;
        
        wp_update_post( $my_post );

    }

}
 
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'doctors_title_updater', 20);

The code works pefectly fine when i'm editing the post from the back-end and hit update. The issue is only when using the submit from the front-end form.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source