Can someone please post an example of php code to execute to return the total votes, and total vote count, on a content type when a yes/no ranking is implemented for it? (NOT using views)

I'm assuming I need to access the voting widget id--if so, how would I get that programmatically?

Comments

mauritsl’s picture

Status: Active » Postponed (maintainer needs more info)

Where do you want to use this code? If it's in a rate widget template, you may simply get the number of votes from $results['count'] (see readme section 4 for more info).

bertboerland’s picture

did the previous answer help? if so, please update. will close ticket in week time otherwise

Weka’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Closing for a lack of response. Feel free to reopen if suggestion in #1 did not help.

carvalhar’s picture

Status: Closed (fixed) » Active

hi. i need to get by php the total count of votes by rate.
i'm using node.tpl for it.

is there a snippet?

thanks

carvalhar’s picture

ok, i found how to do this looking at rate module:

  $results = rate_get_results('node', $node->nid, 1);
 print $results['count']; 

rate module has this function:
/**
* Get results for a voting widget.
*
* @param string $content_type "node" or "comment"
* @param int $content_id Node id (nid) or comment id (cid)
* @param int $widget_id Widget id
* @return array
*/
function rate_get_results($content_type, $content_id, $widget_id)

carvalhar’s picture

Status: Active » Closed (fixed)
naeemshah@coutallure.com’s picture

  $results = rate_get_results('node', $node->nid, 1);
 print $results['count']; 

this code will give toltal count how can i get like coutn and dislike count separate

blogers’s picture

Issue summary: View changes

Yes how get the count a node not all nodes ??

pringlz’s picture

How to render widget by php? How to render all widget programmatically?

pringlz’s picture

Status: Closed (fixed) » Active
pringlz’s picture

Array ( [count] => 1 [rating] => -1 [down] => 1 [up] => 0 [up_percent] => 0 [down_percent] => 100 [user_vote] => -1 )

This is print_r($results)... Where can I get render function?

pringlz’s picture

print rate_embed($node, 'machine_name_of_rate_widget', RATE_FULL);
Its work. Thanks for this .
In views php field other solution not work:

<?php
$widget_id = '1'; // the id of the widget as shown in the url of the rate widget (in this case 1)
print rate_generate_widget($widget_id, 'node', $entity->cid);
?>

from here
Here is tutorial for views vote results by relationships https://modulesunraveled.com/rate/adding-rate-widgets-views

pringlz’s picture

Status: Active » Closed (fixed)