Created
February 18, 2014 06:36
-
-
Save codeboxr/9065686 to your computer and use it in GitHub Desktop.
Code Sample to get rating summary of a post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* If you are in WP loop leave this blank. The id will be automatically inhertited. | |
*/ | |
$postId = ''; | |
/* | |
* If you don't know the rating form ID, please go to the "Rating System"->"Rating Form Listing" page from admin | |
* and get the ID of the rating form. If you yet cannot get the ID leave this blank, the default form will be loaded. | |
*/ | |
$formId = ''; | |
$option = array( 'post_id' => array($postId), 'form_id' => array($formId) ); | |
$average_rating = CBRatingSystem::standalone_singlePost_rating_summary($option); | |
$avgRating = $average_rating[0]; // Here 0 is the array first element key. | |
/* | |
* Output Example : 80 | |
*/ | |
echo $avgRating->per_criteria_rating_summary; | |
/* | |
* After formating the result is: 4.5 out of 5 | |
*/ | |
echo ( ($avgRating->per_criteria_rating_summary/100) * 5)." out of 5</strong> "; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment