Getting data out of Profile2 with field_get_items() I am trying to access my profile2 fields in template.php. I get profiledata, but I also get an error message:


  EntityMalformedException: Missing type profile2. in entity_extract_ids() (row 7663 of /includes/common.inc).


Should not the entity type in field_get_items() be 'profile2', or is it another value?

$profiledata = profile2_load_by_user($variables['comment']-&gt;uid);
$lastname = field_get_items('profile2', $profiledata, 'field_lastname');
As @Clive mentioned profile2_load_by_user() takes user account object not uid, but you also need type name as second argument to retrieve field_lastname using field_get_items function.

I recommend you to use this function profile2_by_uid_load instead of profile2_load_by_user

So your code should look like the following:

$profiledata = profile2_by_uid_load($variables['comment']-&gt;uid, 'profile_type_name');

$lastname = '';

if($profiledata) {

  $lastname  = field_get_items('profile2', $profiledata, 'field_lastname');
}