Hi
I am using drupal 7 and I have printed the user object with the follwing php code.

global $user;
print_r($user);

I am getting the result only with default field values. I have two custom fields and this is not in the result.I have added these custom fields in Home » Administration » Configuration » People » Account settings.Can anybody help me on this.

Thank you in advance

Comments

kunalkursija’s picture

Issue summary: View changes
Status: Active » Needs review

Hi pavimal,

Instead of using global $user; print $user; You will have to do something like this

// Global user.
global $user;
// Logged in user's user id.
$user_id = $user->uid;
// Load the user object instead. (please note that when loading the user, user variable other than $user. This is a special case.)
$user_object = user_load($user_id);

Note:
By default the global user object will contain the basic information of user's login. For ex: login time, session info e.t.c.
However if you want to access complete user object information, Then you will have to load the complete user object. This will also fetch all the fields and respective data.

cilefen’s picture

Status: Needs review » Closed (fixed)

#1 sounds correct to me.

kunalkursija’s picture