fazarcon

make post sticky WPSP

Jul 3rd, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) {
  2. if ( 394283 === $settings['list_id'] ) {
  3. $post_ids = array();
  4. $posts = get_posts($args);
  5. foreach($posts as $post){
  6. $post_ids[] = get_object_vars($post)['ID'];
  7. }
  8. if ( $posts ) {
  9. $move_to_front = array( 87, 282 );
  10. $post_ids_merged = array_merge( $move_to_front, $post_ids );
  11. $reordered_ids = array_unique( $post_ids_merged );
  12.  
  13. $args['post__in'] = $reordered_ids;
  14. $args['orderby'] = 'post__in';
  15. $args['order'] = 'ASC';
  16. }
  17. }
  18. return $args;
  19. },10,2);
Advertisement
Add Comment
Please, Sign In to add comment