Calling the Profile2 fields in Drupal User Profile


If you want to render the Profile fields in your user profile but unable to do so since you have used the Profile2 Module to create profile types then you can make use of this.

Get raw version
  1. <?php
  2. $account = menu_get_object($type = 'user'); // first get the $account info from the current page
  3. $profiles = profile2_load_by_user($account->uid, $type_name = 'YOUR_PROFILE_NAME') ; // load the Profile 2 fields
  4. // note: YOUR_PROFILE_NAME can be set NULL to get all the profile types
  6. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_1']);
  7. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_2']);
  8. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_3']);
  9. print render($user_profile['YOUR_PROFILE_NAME']['view']['profile2'][$profiles->pid]['YOUR_PROFIEL2_FIELD_4']);
  10. ...
  12. // you can put your own div and classes to this page to make your profile look nice.
  13. ?>


paulbooker's picture

Would you indicate how to determine the $user_profile variable?

Thanks, Paul