We are using Drupal 7 and the Profile2 module.

We create and add a value to a field in the profile using this code:

$profile = profile_create(array('type' => 'main', 'uid' => $account->uid));
$profile->field_headline[$lang][0]['value'] = 'Software Engg';

How can we programtically update the user profile field 'field_headline'?

Please advice us.

2 Answers 2


You just need to load the user using drupal function

profile2_load_by_user($account->uid, $type_name = NULL)

$account->uid => user id

$type_name => one of the profile types of profile 2 if any otherwise NULL

   $profile =  profile2_load_by_user($account, $type_name = NULL)
   $profile->field_headline[$lang][0]['value'] = 'update Software Engg';

For more information Click Here

Hope it will work for you!

  • 1
    It is not working when i use for term refrence.
    – Fawwad
    Commented Jan 16, 2015 at 13:32
  • 1
    How would you change the profile2 type to something else? Commented Apr 27, 2015 at 15:21
  • This solution will not work in Drupal hooks such as hook_user_update().
    – arnoldbird
    Commented Apr 6, 2017 at 18:29

Update specific value of user

$user_fields = user_load($user->uid);    
$user_fields->field_points['und'][0]['value'] = $points;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.