Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * [site_reviews class="orderby-rating"]
- */
- add_filter('site-reviews/defaults/reviews/defaults', function ($values) {
- $values['class'] = ''; // ensure the CSS class attribute is available to check for the orderby
- return $values;
- });
- add_filter('site-reviews/query/sql/order-by', function ($orderby, $handle, $sql) {
- if (2 !== count($orderby)) {
- return $orderby;
- }
- if (!in_array('r.is_pinned DESC', $orderby)) {
- return $orderby;
- }
- if (!in_array('p.post_date DESC', $orderby)) {
- return $orderby;
- }
- if (!str_contains(($sql->args['class'] ?? ''), 'orderby-rating')) {
- return $orderby;
- }
- return [
- 'r.is_pinned DESC', // display pinned reviews first
- 'r.rating DESC', // then sort by rating
- 'p.post_date DESC', // then sort by date
- ];
- }, 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement