Drupal 7 Extract Value from User Profile

Posted on 2012-09-04
Last Modified: 2012-09-04
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?
Question by:kjenney
    LVL 17

    Accepted Solution

    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. ' ') ;
    LVL 1

    Author Closing Comment

    Perdect! I should have looked at this function ;)

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Since I am currently running into this issue right now as I type this, I though I would share my experiences with moving a ModX Revolution site from one server to another.  It is not an easy task, but can be accomplished rather easily. The first …
    In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now