Don't like ads? PRO users don't see any ads ;-)
Guest

Relevanssi sticky posts

By: msaari on Aug 8th, 2012  |  syntax: PHP  |  size: 0.54 KB  |  hits: 16  |  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. add_filter( 'relevanssi_hits_filter', 'my_stickyposts_hits_filter' );
  2.  
  3. function my_stickyposts_hits_filter( $data ) {
  4.     $hits = $data[0];
  5.     $regularposts = array();
  6.     $stickyposts = array();
  7.     $query = $data[1];
  8.  
  9.     foreach ( $hits as $key => $hit ) {
  10.         if ($hit->ID == X && $query == "Y")
  11.             $stickyposts[] = $hit;
  12.         else $regularposts[] = $hit;
  13.     }
  14.  
  15.     $filtered_hits = array_merge($stickyposts, $regularposts);
  16.     $filtered_data = array( $filtered_hits, $data[1] );
  17.  
  18.     return $filtered_data;
  19. }