Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Changes the rating parameter of the glsr_get_reviews function to use an absolute rating value
- *
- * @param array $and
- * @param string $handle
- * @param \GeminiLabs\SiteReviews\Database\Query $query
- * @return array
- * @version Site Reviews v5
- */
- function glsr_use_absolute_rating ($and, $handle, $query) {
- $filteredHandles = ['query-review-ids', 'query-total-reviews'];
- if (in_array($handle, $filteredHandles) && !empty($and['rating'])) {
- $and['rating'] = sprintf('AND r.rating = %d', $query->args['rating'] + 1);
- }
- return $and;
- }
- // add the filter before running glsr_get_reviews()
- add_filter('site-reviews/query/sql/and', 'glsr_use_absolute_rating', 11, 3);
- $reviews = glsr_get_reviews(['rating' => 2]);
- // remove the filter after running glsr_get_reviews()
- remove_filter('site-reviews/query/sql/and', 'glsr_use_absolute_rating', 11);
Add Comment
Please, Sign In to add comment