gdrts_aggregate()->items_by_type()

gdrts_aggregate()->items_by_type(
        $entity, $name, $args = array())

Description

Calculate aggregated rating for all items belonging to a specified rating type ($entity and $name). 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.

Parameters

  • $entity: valid entity name for rating type
  • $name: valid name for the $entity for rating type
  • $args: array with additional settings

$args array

  • method: name of the rating method
  • series: name of the series for rating methods that have series
  • id__in: list of ID’s for items to include in the aggregation
  • it__not_id: list of ID’s for items to exclude from the aggregation

Examples

Get aggregated stars rating for all posts/page types

<?php $_aggreation = gdrts_aggregate()->items_by_type(
        'posts', 'page', array('method' => 'stars-rating')); ?>

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

stdClass Object
(
    [rating] => 4.54
    [rating_min] => 4.00
    [rating_max] => 5.00
    [votes] => 18
    [votes_average] => 2.57
    [votes_min] => 1
    [votes_max] => 3
    [items] => 7
)

This means that rating is aggregated from the total of 7 items. Average rating for the set is 4.54, the minimal rating for the individual item in the set was 4.0, and maximal was 5.0. Set has the total of 18 votes, and on average that is 2.57 votes per item, with 1 vote minimum and 3 votes maximum for one item.

Rate this article

You must be logged in to rate this.

0
0
54

Comments

Leave a Reply