Skip to content

Instantly share code, notes, and snippets.

@CamdenSegal
Created October 11, 2014 03:38
Show Gist options
  • Save CamdenSegal/146534b56be8b6bd684f to your computer and use it in GitHub Desktop.
Save CamdenSegal/146534b56be8b6bd684f to your computer and use it in GitHub Desktop.
WP_JSON_CustomPostType Endpoint Generation
class MAP_API_DemoItemType extends WP_JSON_CustomPostType {
protected $base = '/map/demo';
protected $type = 'demo';
public function register_routes( $routes ) {
$routes = parent::register_routes( $routes );
return $routes;
}
}
function map_api_init( $server ) {
global $map_api_demoitemtype;
$map_api_demoitemtype = new MAP_API_DemoItemType( $server );
add_filter( 'json_endpoints', array( $map_api_demoitemtype, 'register_routes' ) );
}
add_action( 'wp_json_server_before_serve', 'map_api_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment