Display (and pass) a custom user field in php In Drupal 7, I've added some custom fields in Account Settings>Manage Fields.  One of them is field_company_name.  I'd like to be able to display this field and pass it to an external php function.

I can easily display the $user fields for the current user.  For example:

&lt;?php
global $user;
echo 'Current User: ';
print_r($user-&gt;name);
echo '&lt;br/&gt;User ID: ';
print_r($user-&gt;uid);
echo '&lt;br/&gt;Email Address: ';
print_r($user-&gt;mail);
echo '&lt;br/&gt;'
?&gt;


How to I get at field_company_name for this same user?
You need to load the user object up fully with user_load(), so the fields get attached:

$account = user_load($GLOBALS['user']-&gt;uid);


Then use field_get_items() to extract the field data:

if ($items = field_get_items('user', $account, 'field_company_name')) {
  $company_name = $items[0]['value'];
}