Support

Account

Home Forums General Issues Update_field not working for front end user creation Reply To: Update_field not working for front end user creation

  • @hube2 I don’t think that is the issue as this error occurs when I update the custom post. I understand why there may be an error if I try to edit from the core WordPress user tab.

    I actually tried to add this if but it actually caused the whole function to not run at all.

    function create_user_frontend( $post_id ) {
    
    	if (get_post_type($post_id) != 'users') {
    
        $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);