Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordPress REST API - Get Random Post endpoint
* Plugin Name: WP Slack REST API Backend
* Description: An example of using the WordPress REST API as a backend for a Slack Bot
* Author: Andy Brudtkuhl
* Author URI:
* Version: 0.1
* Plugin URI:
* License: GPL2+
add_action( 'rest_api_init', function () {
register_rest_route( 'api', '/any', array(
'methods' => 'GET',
'callback' => 'get_random',
) );
function get_random() {
return get_posts( array( 'orderby' => 'rand', 'posts_per_page' => 1) );

This comment has been minimized.

Copy link

meginis commented Sep 25, 2016

Just letting you know you are missing a


on line 18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.