Àpèjúwe
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 APIorderbyenum 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".
Àwọn àwòrán ìbòjú
Ìgbéwọlẹ̀
-
Upload the plugin folder to
/wp-content/plugins/random-posts-for-query-loop-block/
or install it via Plugins Add New Upload Plugin. -
Activate the plugin via Plugins Installed Plugins.
-
Open the Site Editor and edit a template or page containing a Query Loop block.
-
Switch to Code Editor
(top-right kebab menu Code editor). -
Find the
wp:queryblock and set:“orderBy”: “rand”
FAQ
-
No. The dropdown list is defined in Gutenberg’s JavaScript and cannot be modified by PHP alone.
You must edit the block’s attributes in Code Editor. -
Does this affect frontend queries outside the block editor?
-
No. It only extends the REST API schema used by the editor.
WP_Query has natively supportedorderby = 'rand'for many years. -
Does this slow down my website?
-
No extra load is added beyond core WordPress behavior.
However,orderby = randcan be heavy for very large datasets — this is true with or without this plugin.
Àwọn àgbéyẹ̀wò
Kò sí àwọn àgbéyẹ̀wò fún plugin yìí.
Àwọn Olùkópa & Olùgbéejáde
“Random Posts for Query Loop Block” jẹ́ ètò ìṣàmúlò orísun ṣíṣí sílẹ̀. Àwọn ènìyàn wọ̀nyí ti ṣe ìkópa sí plugin yìí.
Àwọn OlùkópaTúmọ̀ “Random Posts for Query Loop Block” sí èdè rẹ.
Ṣe o nífẹ̀ẹ́ sí ìdàgbàsókè?
Ṣàwárí koodu, ṣàyẹ̀wò ibi ìpamọ́ SVN, tàbí ṣe àgbékalẹ̀ sí àkọsílẹ̀ ìdàgbàsókè nípasẹ̀ RSS.
Àkọsílẹ̀ àwọn àyípadà
1.0.5
- Initial release. Adds
randto the REST APIorderbyenum so Query Loop can safely use random order.

