Developer Knowledge Level

This content is intended for WordPress developers, and it may require coding knowledge of WordPress, PHP, and JavaScript. Code examples provided here may contain errors or needs some additional coding. Make sure to test the code before using it on a live website!

        $post_id, $args = array())


Calculate aggregated rating for all comments belonging to a specified post by ID. Array $args contains additional settings. This function return object with the calculated aggregated rating containing rating and votes (and also minimal and maximal rating and posts for individual items in the calculation.


  • $post_id: valid user ID
  • $args: array with additional settings

$args array

  • comment_type: name of the comment type, default: ‘comment’
  • method: name of the rating method
  • series: name of the series for rating methods that have series


Get aggregated stars rating for all comments belonging to post with ID 14:

<?php $_aggreation = gdrts_aggregate()->comments_by_post(
        14, array('method' => 'like-this')); ?>

When you run this, you will get the object with results like this:

stdClass Object
    [rating] => 3
    [rating_min] => 1.00
    [rating_max] => 4.00
    [votes] => 8
    [votes_average] => 2
    [votes_min] => 1
    [votes_max] => 3
    [items] => 4

This is the array with the results for the Like This rating, showing average rating of 3 for the comments belonging to this post.

Rate this reference

You are not allowed to rate this post.

Leave a Comment