Home Forums ACF PRO ACF PRO Registration member Reply To: ACF PRO Registration member

  • Let’s say that you create a select type field with the values

    group_1 : Group 1
    group_2 : Group 2
    group_3 : Group 3
    group_4 : Group 4

    the values are on the left, and that you also create user roles that match the values.

    add_action('acf/save_post', 'add_user_role_from_acf', 20);
    function add_user_role_from_acf($post_id) {
      if (substr($post_id, 0, 5) != 'user_') {
        // not saving a user
      if (empty(get_field('your_field_name', $post_id)) {
        // no value saved in user group field
      $role = get_field('your_field_name', $post_id);
      $user_id = intval(substr($post_id, 5));
      $user = new WP_User($user_id);

    One not is that you would only want to show the field on the new user registration form and not on edit user page because this function would not distinguish between adding a user and updating a user. The field would not be needed in the admin because there if it needed to be changed you would do that using the WP Role setting field.