Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
mauritsl CreditAttribution: mauritsl commentedWhere 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).
Comment #2
bertboerland CreditAttribution: bertboerland commenteddid the previous answer help? if so, please update. will close ticket in week time otherwise
Comment #3
Weka CreditAttribution: Weka commentedClosing for a lack of response. Feel free to reopen if suggestion in #1 did not help.
Comment #4
carvalhar CreditAttribution: carvalhar commentedhi. 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
Comment #5
carvalhar CreditAttribution: carvalhar commentedok, i found how to do this looking at rate module:
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)
Comment #6
carvalhar CreditAttribution: carvalhar commentedComment #7
naeemshah@coutallure.com CreditAttribution: naeemshah@coutallure.com commentedthis code will give toltal count how can i get like coutn and dislike count separate
Comment #8
blogers CreditAttribution: blogers commentedYes how get the count a node not all nodes ??
Comment #9
pringlz CreditAttribution: pringlz commentedHow to render widget by php? How to render all widget programmatically?
Comment #10
pringlz CreditAttribution: pringlz commentedComment #11
pringlz CreditAttribution: pringlz commentedArray ( [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?
Comment #12
pringlz CreditAttribution: pringlz commentedprint rate_embed($node, 'machine_name_of_rate_widget', RATE_FULL);
Its work. Thanks for this .
In views php field other solution not work:
from here
Here is tutorial for views vote results by relationships https://modulesunraveled.com/rate/adding-rate-widgets-views
Comment #13
pringlz CreditAttribution: pringlz commented