Hi all,

I am trying to retrieve one of the custom fields I just setup using the Profile module. For instance, I have created a profile_landing_page text field for each user.

How do I retrieve this field using PHP snippet? I tried $user->profile_landing_page with no success.

Any help greatly appreciated. Thanks,

Alex Saavedra

Comments

alxsvdr’s picture

Nevermind, I just figured out. It seems that $user variable is not loaded with all profile values by default. Thus I invoked profile_load_profile function in order to access custom fields:

global $user;
profile_load_profile($user);
echo "Landing Page: " . $user->profile_landing_page;

Bye,

Alex Saavedra

Sam308’s picture

How do you do it in Drupal 6.x?

What is the php code?

Sam308

iweb’s picture

I found the Drupal6 is the same - you'll need to know the userid of the account your trying to access.

For example, a bit of code I use to retrieve some profile fields is:

$profile_data->uid = $some_uid;                  /* Possibly from $node->uid or $user->uid; */
profile_load_profile($profile_data);             /* Go and get profile info */
print $profile_data->profile_blog_title;         /* output info from profile */

you should probably do some error checking, for example to make sure you actually have something in a field I use

if (isset($profile_data->profile_blog_title)) { ...... }

Simon

radiofranky2009’s picture

Hi,
How do you get the node ID to associate with it's author profile? I tried but it didn't work.
Thanks