Support

Account

Home Forums General Issues Update_field causing critical error Reply To: Update_field causing critical error

  • I wonder if somebody can help with something I cannot work out.
    I basically have a front end form to create users using ACF fields. I also have a field which I am using ‘Update_field’ for.
    This all works for creating the user, however when I update this same custom post I get a critical error, caused by the ‘Update_field’ element specifically.
    The critical error is:
    Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in

    And here is my code:

    function create_user_frontend( $post_id ) {
        $first_name = get_field('first_name', $post_id);
        $last_name = get_field('last_name', $post_id);
     $username = get_field('email', $post_id);
     $password = get_field('password', $post_id);
     $incident = get_field('related_incident', $post_id, false);
     $role = get_field ('role', $post_id);
     $userdata= array (
     'user_login' => $username,
     'user_email' => $username,
     'first_name' => $first_name,
     'last_name' => $last_name,
     'user_pass' => $password,
     'role' => $role,
     );
     $user_id = wp_insert_user($userdata);
     update_field('field_602ce62b11720', $incident, 'user_'.$user_id);
     }
    add_action('acf/save_post', 'create_user_frontend', 20);