To search and filter rating items, GD Rating System includes easy to use object, that will construct and run the rating query. This object allows you to set various query arguments to fine tune the results.

Object name is ‘gdrts_core_query’. To get the initialized object, you can use the function gdrts_query() that will return already prepared object, but you can make your own instance too. This object has an own main method that will prepare and run the query, and return results.

Basic usage:

$args = array(); // list of arguments
$ratings = new gdrts_core_query();
$results = $ratings->run($args);

Variable $args needs to be an array that includes a list of arguments you want to use to filter and order list or results.

Supported arguments

Here are the supported arguments:

  • method – the name of the rating method to use, default is ‘stars-rating’.
  • series – the name of the rating series for emote-this rating method.
  • entity – the name of the rating type entity.
  • name – the name of the rating type.
  • id__in – a list of rating item ID’s to limit the results.
  • id__not_in – a list of rating item ID’s to exclude.
  • orderby – the column to use for sorting: item, id, latest, up, down, votespercentage, sum, rating. The default is ‘rating’.
  • order – a sorting order: DESC or ASC, default is DESC.
  • offset – the number of results to skip, default is 0.
  • limit – the number of results to return, default is 5.
  • return – what format of data to return: objects, ids and quick. Default is ‘objects’.
  • rating_min – a minimum rating to consider for filtering. The default is 0.
  • votes_min – a minimum number of votes to consider for filtering. The default is 1.
  • object – additional data for filtering the rating items.

Some values for orderby are for the Thumbs Rating method only: up and down.

Object argument

The last argument called ‘object’ is an array for specifying additional filters specific to the rating items original data (posts, terms…).

This argument is available in Pro version of the plugin only!

Object array supports these elements, and each one can be an array with values:

  • status: publish status for posts, by default ‘publish’ and ‘closed’.
  • author: a list of IDs of the authors for posts or comments.
  • meta: a simple associative array of meta key names and values.
  • terms: a list of IDs of the terms for posts.

Usage Examples

Here are few examples for the query object.

// Get top 10 thumbs rating posts ordered by UP ratings
$args = array(
  'method' => 'thumbs-rating',
  'limit' => 10,
  'orderby' => 'up',
  'entity' => 'posts',
  'name' => 'post'
$ratings = new gdrts_core_query();
$results = $ratings->run($args);
// Get top 5 stars rating posts, by selected authors and with listed terms
$args = array(
  'method' => 'thumbs-rating',
  'entity' => 'posts',
  'name' => 'post',
  'object' => array(
    'author' => array(1, 3, 10),
    'terms' => array(5, 7, 53),
$ratings = new gdrts_core_query();
$results = $ratings->run($args);
Rate this article

You are not allowed to rate this post.


Leave a Reply