Summary
Random Posts for Query Loop Block is a free lightweight WordPress plugin that lets you safely use random ordering inside the Query Loop block, without breaking the Site Editor preview.
What This Plugin Does
WordPress does not allow “orderby”: “rand” when a Query Loop block requests posts through the REST API.
This causes the Site Editor to fail with JSON errors if you manually set the Query Loop to use a random order.
This plugin fixes that by extending the REST API schema to include “rand” as a valid orderby value for posts and pages.
Key Features
- Enables random post ordering (orderby=rand) inside the Query Loop block
- Prevents invalid parameter and editor preview errors
- Simple and lightweight. No settings or UI bloat.
- Works with posts and pages out of the box
- Fully compatible with Gutenberg and the Site Editor
How It Works
Query Loop blocks rely on the WordPress REST API.
By default, the API rejects orderby=rand because it’s not listed as an allowed enum. This plugin:
- Hooks into rest_{$post_type}_collection_params
- Appends “rand” to the orderby enum
- Lets Gutenberg pass orderby=rand safely
- Allows the editor preview to load normally
That’s it. No extra configuration needed.
How to Use
- Install the plugin.
- Add a Query Loop block using the visual/ Guttenberg editor.
- Open Code Editor (top-right menu → Code editor)
- Change the block’s ordering to: “orderBy”: “rand”
- Update the page/post and preview. Your posts will now load in random order. If the plugin is not installed, you will see a loading spinner in place of your added query loop block.
Note: WordPress doesn’t yet show “Random” in the sidebar ordering dropdown. You must enter it via Code Editor.
(Custom post type support may be added in future versions.)
Download & Installation
You can download the plugin from the official WordPress.org directory.
About the Developer
This plugin is created and maintained by Abhay Rautela, a UX Architect (Cone Trees), music producer and deejay.
Support the Plugin
This plugin is free to use. If you find it helpful and want to support continued maintenance and future improvements, you can do so here: