Anyone manage to work entity metadata wrapper with profile2 entity? Code:

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

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

$wrapper-&gt;field_first_name-&gt;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.
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-&gt;field_first_name-&gt;set(devel_generate_word(mt_rand(6, 12)));