Skip to content

Instantly share code, notes, and snippets.

@carl-alberto
Last active September 29, 2016 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carl-alberto/323ae3543f6f7728936db6785a476c7a to your computer and use it in GitHub Desktop.
Save carl-alberto/323ae3543f6f7728936db6785a476c7a to your computer and use it in GitHub Desktop.
WordPress REST API - This will return variables of 2 or more
add_action( 'rest_api_init', function () {
register_rest_route(
'testapi/v1', '/getvars/(?P<var1>\d+)/(?P<var2>\d+)', array(
'methods' => 'GET',
'callback' => 'wp_restapi_getvars',
)
);
}
);
function wp_restapi_getvars( $data ) {
echo 'This is var1:' . $data['var1'] . '<br>';
echo 'This is var2:' . $data['var2'] . '<br>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment