Advertisement
rAthus

[WordPress] Revolution Slider - display sticky posts first

Oct 3rd, 2022
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. /* Revolution Slider - display sticky posts first - by Arkanite */
  4. function revslider_sticky_posts_first($query, $slider_id) {
  5.     // only apply the special filter for slider with "x" ID
  6.     // http://prntscr.com/r3ovyu
  7.    
  8.     // create du duplication of the query that looks for sticky posts only
  9.     $query_sticky = $query;
  10.     $query_sticky['post__in'] = get_option('sticky_posts');
  11.     $query_sticky['fields'] = 'ids';
  12.     $query_sticky = new WP_Query($query_sticky);
  13.    
  14.     // create du duplication of the query that looks for non-sticky posts only
  15.     $query_others = $query;
  16.     $query_others['post__not_in'] = get_option('sticky_posts');
  17.     $query_others['fields'] = 'ids';
  18.     $query_others = new WP_Query($query_others);
  19.    
  20.     // merge the post ids of these two queries' retults, starting with the sticky ones
  21.     $idz = array_merge($query_sticky->posts,$query_others->posts);
  22.    
  23.     // order the original query to look for these ids in this specific order
  24.     $query['post__in'] = $idz;
  25.     $query['orderby'] = 'post__in';
  26.     $query['order'] = 'ASC';
  27.     $query['ignore_sticky_posts'] = 0;
  28.     $query['tax_query'] = false;
  29.    
  30.     return $query;
  31. }
  32. add_filter('revslider_get_posts', 'revslider_sticky_posts_first', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement