I am interested in getting the average count for a node. Currently I am able to show the nodes rating with:

$fivestar = field_view_field('node', $node, 'field_cg_rating', 'basic');

But I just want to get the count instead of the entire html showing the vote. Just a numerical value.

Is there an easy way of doing this?


You can calc it with formula which is used by Fivestar on theme layer: http://drupalcode.org/project/fivestar.git/blob/refs/heads/7.x-2.x:/includes/fivestar.theme.inc#l132

$fivestar = field_view_field('node', $node, 'field_cg_rating');
$stars = 5; // Stars count from your field instance settings. Settings can be loaded with field_info_instance() if needed.
$rating = round(($fivestar['#items'][0]['average']/100) * $stars, 1);
| improve this answer | |
  • this should get me going in the right direction. I'll fiddle around with it. Cheers. +1 – John Riselvato Dec 20 '12 at 20:54
  • Just an fyi, using $fivestar['#items'][0]['average'] is incorrect unfortunately. – John Riselvato Dec 21 '12 at 17:10
  • $fivestar['#items'][0]['average'] always returns zero. – John Riselvato Dec 21 '12 at 21:32
  • Please, dump $fivestar['#items']. – kalabro Dec 22 '12 at 10:42

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.