Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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