0

Code:

$profile = profile2_load_by_user($account);
$profile = $profile['main'];

$wrapper = entity_metadata_wrapper('profile2_type', $profile);

$wrapper->field_first_name->set(devel_generate_word(mt_rand(6, 12)));

I'm sure that $profile is Profile object. Beside 'profile2_type' I tried 'profile', 'profile2' but got error too.

Current error:

Unknown data property field_first_name.

0
0
$profile = profile2_load_by_user($account);
$wrapper = entity_metadata_wrapper('profile2', $profile);
1

The problem is that profile2_load_by_user() returns an array of all user profiles by default, whereas entity_metadata_wrapper() needs a single entity object.

Try loading a single profile:

$profile = profile2_load_by_user($account, 'profile_name');
$wrapper = entity_metadata_wrapper('profile2', $profile);
$wrapper->field_first_name->set(devel_generate_word(mt_rand(6, 12)));
1

I don't know if something changed since '15, but I had to make an adjustment to the accepted answer to get this to work for a specific profile, e.g., presuming profile2_type is the machine name of a defined profile:

$profile = profile2_load_by_user($account, 'profile2_type');
$wrapper = entity_metadata_wrapper('profile2', $profile->pid);

Or, alternatively:

$profile = profile2_load_by_user($account);
$wrapper = entity_metadata_wrapper('profile2', $profile['profile2_type']->pid);

Note the specific reference to the profile ID.

0

$profile = profile2_load_by_user($user->uid,'profile_type');this will declare a single object from the logged in user

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .