BACK TO DIRECTORY

Random Posts for Query Loop Block

by Abhay Rautela

0.0
(0 ratings)

The Query Loop block in WordPress does not include a “Random” ordering option in the sidebar UI.
However, WordPress core does support orderby = rand in WP_Query.

The problem:
Using "orderBy": "rand" inside a Query Loop block can cause the Site Editor preview to fail, because rand is not included in the REST API schema for posts.

This plugin fixes that by extending the REST API orderby enum so the editor recognizes "rand" as valid.

✔ What this plugin does

  • Adds "rand" to the REST API orderby enum for posts and pages.
  • Allows the Query Loop block to use "orderBy": "rand" safely.
  • Prevents JSON errors and broken previews in the Site Editor.
  • Makes “random post” layouts work reliably both in the editor and frontend.

⚠ What this plugin does not do

  • It does not add a “Random” option to the Query Loop UI dropdown.
    (That UI is defined in Gutenberg’s JavaScript.)
  • You must still set "orderBy": "rand" manually using the Code Editor.

Example use case

Want your homepage, blog, quotes site, testimonials, or featured-section to show
a different post every time the page loads?

Install this plugin open the template switch to Code Editor set "orderBy": "rand".

Screenshots

Query Loop block configured with "orderBy": "rand" in the Code Editor.

Query Loop block configured with "orderBy": "rand" in the Code Editor.

Site Editor preview working correctly with random post ordering enabled.

Site Editor preview working correctly with random post ordering enabled.

Plugin Details

Active Installs
20
Total Downloads
377
Version
1.0.5
Requires WP
6.0
Requires PHP
7.4
Tested Up To
6.9.7
Added
2026-01-07
Last Updated
2026-01-07 8:22pm GMT

Ratings

5
0
4
0
3
0
2
0
1
0