| 开发者 | ctrs |
|---|---|
| 更新时间 | 2026年1月8日 04:27 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 6.9 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
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
"rand" to the REST API orderby enum for posts and pages."orderBy": "rand" safely."orderBy": "rand" manually using the Code Editor."orderBy": "rand".
/wp-content/plugins/random-posts-for-query-loop-block/\
or install it via Plugins → Add New → Upload Plugin.wp:query block and set:"orderBy": "rand"
Example:
```
```
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.
No. It only extends the REST API schema used by the editor.\
WP_Query has natively supported orderby = 'rand' for many years.
No extra load is added beyond core WordPress behavior.\
However, orderby = rand can be heavy for very large datasets — this is true with or without this plugin.
rand to the REST API orderby enum so Query Loop can safely use random order.