Title: Query Loop: Random Selection Of Posts
Last modified: May 2, 2023

---

# Query Loop: Random Selection Of Posts

 *  Resolved [David Adams](https://wordpress.org/support/users/tictag/)
 * (@tictag)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/query-loop-random-selection-of-posts/)
 * I am trying to create a grid of randomly selected posts from a pool of such posts,
   so that every time the page is rendered, a new grid is rendered.
 * Is this possible with, for example, Query Loop?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [David Adams](https://wordpress.org/support/users/tictag/)
 * (@tictag)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/query-loop-random-selection-of-posts/#post-16703945)
 * After further troubleshooting…
 * Within your [documentation](https://docs.generateblocks.com/article/query-loop-overview/),
   you mention that the Query Loop block makes use of the standard WordPress WP_Query()
   function, which does have the ability to return a random set of posts: `'orderby'
   => 'rand',` according to [here](https://developer.wordpress.org/reference/classes/wp_query/),
   but the UI does not have this option.
 * Is it possible to modify the Query Loop query outside of the UI or maybe add 
   this option to the UI?
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/query-loop-random-selection-of-posts/#post-16704526)
 * Hi there,
 * its an option in GenerateBlocks Pro, it accompanies the “Current Post” related
   args.
   But you can use the `generateblocks_query_loop_args` hook to merge your
   own args if you want:
 *     ```wp-block-code
       add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
           // give the grid block inside the query loop a class name of
           $myClass = 'my-class-name';
           if (
               ! empty( $attributes['className'] ) &&
               strpos( $attributes['className'], $myClass ) !== false &&
           ) {
           // Merge the current $query_args with editor defined args
           return array_merge( $query_args, array(
               'orderby' => 'rand',
           ) );
           }
   
           return $query_args;
       }, 10, 2 );
       ```
   
 * Note: the `rand` process can be a server performance hog and some hosts disable
   it for the amount of staring it places on a database query. So you may need to
   check with the host if it doesn’t work.
 *  Thread Starter [David Adams](https://wordpress.org/support/users/tictag/)
 * (@tictag)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/query-loop-random-selection-of-posts/#post-16705480)
 * There was stray ‘&&’ in there but this works perfectly!! 🤩
 * Thank you so much!
 *  Plugin Support [David](https://wordpress.org/support/users/diggeddy/)
 * (@diggeddy)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/query-loop-random-selection-of-posts/#post-16711291)
 * Ah, good spot.
   Glad to hear that worked.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Query Loop: Random Selection Of Posts’ is closed to new replies.

 * ![](https://ps.w.org/generateblocks/assets/icon.svg?rev=3239461)
 * [GenerateBlocks](https://wordpress.org/plugins/generateblocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/generateblocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/generateblocks/)
 * [Active Topics](https://wordpress.org/support/plugin/generateblocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/generateblocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/generateblocks/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * 4 replies
 * 2 participants
 * Last reply from: [David](https://wordpress.org/support/users/diggeddy/)
 * Last activity: [2 years, 11 months ago](https://wordpress.org/support/topic/query-loop-random-selection-of-posts/#post-16711291)
 * Status: resolved