• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 796
  • Last Modified:

Drupal 7 Extract Value from User Profile

I'm building a Drupal 7 module and I'd like to obtain the value of a custom user field (field_zipcode). How can I get the value and import into an array?
0
kjenney
Asked:
kjenney
1 Solution
 
nanharbisonCommented:
I didn't create this, I had found it one before:
//first load the global "user"
global $user;
 
//load the current users custom fields (you could get another uid's fields if you want)
$user_fields = user_load($user->uid);
 
//get the value you need from the array, by specifying the "system name" you used in drupal
$customfield = $user_fields->field_custom['und']['0']['value'];
 
//use the value
print  t("Custom field value is " . $customfield. ' ') ;
0
 
kjenneyAuthor Commented:
Perdect! I should have looked at this function ;)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now