Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $args = array(
- 'post_type' => 'post',
- 'posts_per_page' => -1,
- 'orderby' => 'publish_date',
- 'order' => 'DESC',
- '_shuffle_and_pick' => 3 // <-- our custom argument
- );
- $loop = new WP_Query( $args );
- add_filter( 'the_posts', function( $posts, WP_Query $query )
- {
- if( $pick = $query->get( '_shuffle_and_pick' ) )
- {
- shuffle( $posts );
- $posts = array_slice( $posts, 0, (int) $pick );
- }
- return $posts;
- }, 10, 2 );
Add Comment
Please, Sign In to add comment