Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress REST API - Get Random Post endpoint
<?php
/**
* 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: http://youmetandy.com
* Version: 0.1
* Plugin URI: https://github.com/abrudtkuhl/heykramer
* 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) );
}
@meginis

This comment has been minimized.

Copy link

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.