Advertisement
geminilabs

Untitled

Mar 24th, 2025 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. /**
  2.  * [site_reviews class="orderby-rating"]
  3.  */
  4.  
  5. add_filter('site-reviews/defaults/reviews/defaults', function ($values) {
  6.     $values['class'] = ''; // ensure the CSS class attribute is available to check for the orderby
  7.     return $values;
  8. });
  9.  
  10. add_filter('site-reviews/query/sql/order-by', function ($orderby, $handle, $sql) {
  11.     if (2 !== count($orderby)) {
  12.         return $orderby;
  13.     }
  14.     if (!in_array('r.is_pinned DESC', $orderby)) {
  15.         return $orderby;
  16.     }
  17.     if (!in_array('p.post_date DESC', $orderby)) {
  18.         return $orderby;
  19.     }
  20.     if (!str_contains(($sql->args['class'] ?? ''), 'orderby-rating')) {
  21.         return $orderby;
  22.     }
  23.     return [
  24.         'r.is_pinned DESC', // display pinned reviews first
  25.         'r.rating DESC',    // then sort by rating
  26.         'p.post_date DESC', // then sort by date
  27.     ];
  28. }, 10, 3);
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement