Drupal - Content Profile Node from UID

Kevin's picture

[b]Q:[/b] How do I load a user's [url=http://drupal.org/project/content_profile]Content Profile[/url] node in PHP given their UID or user object?
[b]A:[/b] Use the function content_profile_load() to load the associated profile node.

The [url=http://drupal.org/project/content_profile]Content Profile[/url] module is very handy, it allows you to create user profiles using the CCK and all of the nice field types and display options that comes with it - often it is a much better option than the default drupal profile module, using it you should be able to craft a much more sophisticated user profile & profile page that probably fits in better with your target web design.

But given a user, or user id (uid) how is it possible to programmatically load the user's associated profile node, there is no mention of it in the user object?

Luckly the module provides a function to do this for you:


content_profile_load($type, $uid, $lang = '')

(details [url=http://drupalcontrib.org/api/function/content_profile_load/6]here[/url]).

the $type argument is the content type name used to store the profile data, by default this is just 'profile'. The second argument takes the target user id. So it could be called like this:


$profile_node = content_profile_load('profile', $user->uid);

or if you already have the UID:


$profile_node = content_profile_load('profile', $uid);

Aftr that $profile_node is just a regular node and its fields can be queried in the usual way. A handy way see what its fields are is to install the [url=http://drupal.org/project/devel]devel[/url] module and pop dvm($profile_node); somwehere in your code, this should print the variable's structure to the screen.

I had to search for how to do this for a while, so I hope this post helps somebody in a similar situation!

Share this post: 

Recent Work

Some of Ireland's biggest brands use Pride Design to Design, Build, Manage, Market and Maintain their websites.

Website design for St.Patricks Credit Union in Dublin, Including Loan Calculators.

Website design and development for a step by step wedding and other stationary ordering website f

New website designed and developed for Cork's newest café, which is based in Merchants Quay in Co

New Website design for Pain Relief clinic based in Cork City.

Website for a busy Dublin city centre pub.

We redrafted the Ballymaloe house website to modernise the look and feel of the site and to also

We revamped the website for the Ballymaloe Cookery School.

We revamped the Cully & Sully website onto Drupal.

Rachel Allen was brought up in Dublin and left home at eighteen to study at the world-famous Ball

Clóna Dairy Products are a Dairy Company based in Clonakilty, Co. Cork, since 1919.

Project Arts Centre is Ireland’s leading centre for the presentation and development of c