Guest User

Untitled

a guest
Feb 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. $args = array(
  2. 'post_type' => 'post',
  3. 'posts_per_page' => -1,
  4. 'orderby' => 'publish_date',
  5. 'order' => 'DESC',
  6. '_shuffle_and_pick' => 3 // <-- our custom argument
  7. );
  8. $loop = new WP_Query( $args );
  9.  
  10. add_filter( 'the_posts', function( $posts, WP_Query $query )
  11. {
  12. if( $pick = $query->get( '_shuffle_and_pick' ) )
  13. {
  14. shuffle( $posts );
  15. $posts = array_slice( $posts, 0, (int) $pick );
  16. }
  17. return $posts;
  18. }, 10, 2 );
Add Comment
Please, Sign In to add comment