2

I am trying to retrieve some fields from my Profile 2 profile but am not sure how I should connect the table dr_field_data_field_resources to its relevant user.

In profile it is possible to add a field term_reference 'resources', then I want to be able to retrieve those values in an array based on a user I specify. I did see some other docs for profile2_load, but I using an example turorial. I am getting called to undefined function for profile2_load().

$userskillsresources = db_query("SELECT dr_users.name as 'username', dr_taxonomy_term_data.name  as 'userresourceterm'
    FROM dr_users
    JOIN dr_field_data_field_resources
    JOIN dr_profile ON dr_users.uid = dr_profile.uid
    JOIN dr_taxonomy_term_data ON dr_field_data_field_resources.field_resources_tid = dr_taxonomy_term_data.tid
    WHERE dr_users.uid = '10'")->fetchAssoc();

1 Answer 1

2

If you really do have Profile2 installed and enabled, then you shouldn't get getting undefined function errors. Double check that it is enabled.

Otherwise, you are going about this in the wrong way. You really don't need to do queries like this. Leverage the API:

$account = user_load(10);
$profile = profile2_load_by_user($account);

If you have a single profile for the user, $profile will be a node object. Otherwise, it will be an array of nodes. Then you can do something like:

$resources = field_get_items('node', $profile, 'field_resources', $profile->language);

Also take a look at this article for a handy helper function or read more about the Field API. If $resources are taxonomy terms, then take a look at taxonomy_term_load for loading the associated terms.

6
  • Hi, I am getting Call to undefined function user_load() and it says for definite that profile2 is installed and enabled... Sep 1, 2012 at 23:07
  • would it not work if I was logged in as admin? Sep 1, 2012 at 23:10
  • If you are getting an undefined function for user_load then you have a serious problem elsewhere. Off the top of my head I am not sure how I would go about debugging this, other than starting to disable anything custom I did to the site.
    – mpdonadio
    Sep 2, 2012 at 2:13
  • Hi, I didn't do anything custom to the site. Sep 2, 2012 at 13:41
  • I am still getting this error. Any suggestions as to steps to take to debug it. Sep 2, 2012 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.