Skip to main content
improved formatting and grammar
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

You can equally use either [user_save][1]user_save() or [field_attach_update][2]field_attach_update().

// Load the user's account.
global $user;
$account = user_load($user->uid); // Load user's account
$edit = $account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
user_save($account, $edit);
// field_attach_update
$account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
field_attach_update('user', $account);

The difference between those twousing one function or the other is that user_saveuser_save() will update all the user fields whereas field_attach_updatefield_attach_update() will update only the specified field. [1]: https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_save/7.x [2]: https://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_update/7.x

You can equally use either [user_save][1] or [field_attach_update][2]

global $user;
$account = user_load($user->uid); // Load user's account
$edit = $account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
user_save($account, $edit);
// field_attach_update
$account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
field_attach_update('user', $account);

The difference between those two is that user_save will update all user fields whereas field_attach_update will update only the specified field. [1]: https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_save/7.x [2]: https://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_update/7.x

You can equally use either user_save() or field_attach_update().

// Load the user's account.
global $user;
$account = user_load($user->uid);
$edit = $account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
user_save($account, $edit);
// field_attach_update
$account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
field_attach_update('user', $account);

The difference between using one function or the other is that user_save() will update all the user fields whereas field_attach_update() will update only the specified field.

Source Link
mchar
  • 1.7k
  • 1
  • 11
  • 20

You can equally use either [user_save][1] or [field_attach_update][2]

global $user;
$account = user_load($user->uid); // Load user's account
$edit = $account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
user_save($account, $edit);
// field_attach_update
$account->field_my_custom_field[LANGUAGE_NONE][0][value] = $new_value;
field_attach_update('user', $account);

The difference between those two is that user_save will update all user fields whereas field_attach_update will update only the specified field. [1]: https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_save/7.x [2]: https://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_update/7.x