I am evaluating some custom code in a rule. I want to get a list of users, then load all of the associated profiles from the profile2 module. My code below, loads all the users, and I got an array of the UIDs to put into the profile_load_multiple() function but it is just returning one user profile, I want to return all profiles. Eventually I want to compare a term from a field (project resources) in the node 'project' I am creating with a field (resources) that is in each user main profile. My intention is using rules to accomplish this.

$users = entity_load('user');
$arrayuids = array();
foreach ($users as $user)
array_push($arrayuids, $user->uid);
$profile = profile2_load_multiple($arrayuids, FALSE);
  • Consider using Views Bulk operations module + Rules for jobs like this.
    – AKS
    Sep 9, 2012 at 17:50

1 Answer 1


Your first problem is that you send uids instead of pids. First argument of profile2_load_multiple is $pids which are profile2 ids.

Try this code:

$users = entity_load('user');
$arrayuids = array_keys($users);

$query = new EntityFieldQuery();    
$query->entityCondition('entity_type', 'profile2')
    ->propertyCondition('uid', $arrayuids, 'IN');

$profile = $query->execute();


I haven't tested it but it should work.

  • Hi, how would I iterate through the output of $profile? It is ... (Array, 1 element) profile2 (Array, 3 elements) 1 (Object) stdClass 2 (Object) stdClass 3 (Object) stdClass Sep 10, 2012 at 14:21
  • I am trying to get the contents with foreach($profile as $obj => $value){ dpm($value->pid); } but this gives an error Sep 10, 2012 at 15:04
  • foreach($profile as $obj){ foreach($obj as $objinner) { dpm($objinner->pid); } } Sep 10, 2012 at 15:34
  • Take a look at this tutorial on how to use EntityFieldQuery drupal.org/node/1343708 Sep 11, 2012 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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