WP Manifestindependent plugin directory
manifest / developer / wpgraphql-random-orderby

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

0stars
0forks

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.zip

Readme

=== 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 ==

  1. Upload the wpgraphql-random-orderby folder to /wp-content/plugins/.
  2. Activate the plugin through the "Plugins" menu in WordPress.
  3. Make sure WPGraphQL is installed and active.
  4. Use RAND as 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.

Read the full README on GitHub →