WPGraphQL Random Orderby
Adds RAND (random) as an orderby option for WPGraphQL post queries.
by Seniors <https://www.seniors.com.co/> · github.com/dazza-dev/wpgraphql-random-orderby
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/dazza-dev/wpgraphql-random-orderby/archive/refs/heads/main.zipReadme
=== WPGraphQL Random Orderby === Contributors: seniors Tags: wpgraphql, graphql, random, orderby, query Requires at least: 5.0 Tested up to: 6.8 Requires PHP: 7.4 Stable tag: 1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html
Adds RAND (random) as an orderby option for WPGraphQL post queries.
== Description ==
By default, WPGraphQL does not support random ordering for posts. This lightweight plugin adds RAND to the PostObjectsConnectionOrderbyEnum, allowing you to retrieve posts in random order via GraphQL queries.
Requires WPGraphQL plugin to be installed and active.
= Usage =
Once activated, you can use RAND in your GraphQL queries:
query GetRandomPosts { posts(where: { orderby: { field: RAND } }) { nodes { id title slug } } }
== Installation ==
- Upload the
wpgraphql-random-orderbyfolder to/wp-content/plugins/. - Activate the plugin through the "Plugins" menu in WordPress.
- Make sure WPGraphQL is installed and active.
- Use
RANDas an orderby field in your GraphQL queries.
== Frequently Asked Questions ==
= Does this plugin require WPGraphQL? =
Yes. This plugin extends WPGraphQL by adding a new orderby enum value. It will have no effect without WPGraphQL active.
= Does it work with custom post types? =
This plugin only adds random ordering for the default posts connection. To support custom post types, you would need to add the corresponding filter for each CPT (e.g., graphql_{YourCPT}ConnectionOrderbyEnum_values).
== Changelog ==
= 1.0 =
- Initial release.
- Adds RAND orderby option to WPGraphQL post queries.