This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

relevanssi_hits_filter

By: maxhodges0 on Sep 4th, 2012  |  syntax: PHP  |  size: 0.71 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /** Relevanssi customization by max **/
  2. add_filter('relevanssi_hits_filter', 'order_the_results');
  3.  
  4. function order_the_results($hits) {
  5.     global $wp_query;
  6.     if ($wp_query->query_vars['orderby'] == 'likes') {
  7.         $likes = array();
  8.         foreach ($hits[0] as $hit) {
  9.                 $likecount = get_post_meta($hit->ID, '_likes', true);
  10.                 if (!isset($likes[$likecount])) $likes[$likecount] = array();
  11.                 array_push($likes[$likecount], $hit);
  12.         }
  13.         ksort($likes);
  14.         $sorted_hits = array();
  15.         foreach ($likes as $likecount => $year_hits) {
  16.                 $sorted_hits = array_merge($sorted_hits, $year_hits);
  17.         }
  18.         $hits[0] = $sorted_hits;
  19.     }
  20.     return $hits;
  21. }
clone this paste RAW Paste Data