Challenge:
- I have a profile2 taxonomy term reference field (single select) on user profiles called "field_member_interest_group".
- On save/update of the user profile, I wan to A) See if the user has a role of "Elephant", then if so, select the term of "Elephant Group" from that user's taxonomy term reference field and save the changes.
- "MYMODULE" is the name of my module in lowercase.
My (not working) Code:
function MYMODULE_user_update(&$edit, $account, $category) {
$account = user_load($account->uid);
$profile_profile = profile2_load_by_user($account->uid, 'profile');
$profile_wrapper = entity_metadata_wrapper('profile2', $profile_profile->pid);
if (in_array('Elephant', $account->roles)) {
$termX = 3942; //tid of "Elephant Group"
}
$profile_wrapper->field_member_interest_group->set($termX);
//Save changes to the profile entity
$profile_wrapper->save();
}
Problem:
The changes are not saved to the user account, they are ignored completely.
Any thought on what could be going wrong?