[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 = '')
$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);
$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!