Skip to content

Instantly share code, notes, and snippets.

@jesseeproductions
Last active November 16, 2016 19:10
Show Gist options
  • Save jesseeproductions/dd8605dc97a28c5062c3a26eb6dc3237 to your computer and use it in GitHub Desktop.
Save jesseeproductions/dd8605dc97a28c5062c3a26eb6dc3237 to your computer and use it in GitHub Desktop.
The Events Calendar Basic Custom Query EndPoint Example
/**
* The Events Calendar Basic Custom Query EndPoint Example
*
* @param $data
*
* @return array|null
*
* Get Events from December 31st to January 20th - <a href="http://yoursite.org/wp-json/tribe_events/v2/events/custom/2015-12-31/2016-01-20" rel="nofollow">http://yoursite.org/wp-json/tribe_events/v2/events/custom/2015-12-31/2016-01-20</a>
*
* jQuery.get( "http://yoursite.org/wp-json/tribe_events/v2/events/custom/2015-12-31/2016-01-20", function( response ) {
console.log(response);
} );
*/
function tribe_api_query( $query ) {
$events = tribe_get_events( array(
'eventDisplay' => $query['eventDisplay'],
'start_date' => $query['start_date'],
'end_date' => $query['end_date']
) );
if ( empty( $events ) ) {
return null;
}
return $events;
}
add_action( 'rest_api_init', function () {
register_rest_route( 'tribe_events/v2', '/events/(?P<eventDisplay>[a-z\-]+)/(?P<start_date>[a-z0-9\-]+)/(?P<end_date>[a-z0-9\-]+)', array(
'methods' => 'GET',
'callback' => 'tribe_api_query',
) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment