I was able to “create” the following code:
<?php
$args = array(
'numberposts' => -1, // all the posts
'post_type' => 'post',
'category' => $cat,
'meta_key' => 'ratings_average',
'meta_value' => null,
'meta_compare' => '!='
);
$posts = get_posts( $args );
$votes = 0;
$post_count = count($posts);
$rating = 0;
$average = 0;
foreach( $posts as $post ) {
$single = get_post_meta( $post->ID, 'ratings_average', true );
$rating += $single;
}
foreach( $posts as $post ) {
$single = get_post_meta( $post->ID, 'ratings_users', true );
$votes += $single;
}
$average = $rating / $post_count;
echo 'Average rating for the category:<br />';
echo round($average, 2);
echo '<br />';
echo 'Number of votes:<br />';
echo $votes;
?>
Basically it gathers all average ratings for the posts in certain category, number of total votes for all posts and number of posts which have ratings.
Then to calculate the average rating for the category we devide the sum of all average ratings by the number of posts which have ratings. I think it’s a some kind of a solution since the plugin doesn’t have the ability to rate a category. So my question is:
How to add starts to that rating? Is there something like a shortcode or snippet in the plugin if you input a value and the output is that value converted in stars ??