I am using rate module where users can plus or minus the articles created by an author. Now, in the profile page of the author, I want to display the total number of votes he/she has got from all his articles. Is there any way to do this without using db_query ? Thank you.

1 Answer 1


I think it would be pretty expensive to do this without writing your own query, but here is one way you could do it:

Use EntityFieldQuery to build a list of nids created by the current author. Something like this:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'article');
  ->propertyCondition('uid', '1')
$nodes = $query->execute();

Then parse the nids returned into a seperate array and use that array as a criteria parameter in votingapi_select_votes(). Something like:

$votes = votingapi_select_votes('entity_id' => $nid_array);

I'm not 100% sure that votingapi_select_votes() accepts an array for the $criteria['entity_id'] param. You might need to loop through each nid if it doesn't.

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.