Calling the Profile2 fields in Drupal User Profile

Public

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.

</> CopyGet raw version
php
  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
  5.  
  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. ...
  11.  
  12. // you can put your own div and classes to this page to make your profile look nice.
  13. ?>

Comments

paulbooker's picture

Would you indicate how to determine the $user_profile variable?

Thanks, Paul