I'm trying to register a GET REST API route with multiple parameters with the following code:
register_rest_route( 'myplugin/v1', '/posts/?number=(?P<number>[\d]+)&offset=(?P<offset>[\d]+)&total=(?P<total>[\d]+)', array(
'methods' => 'GET',
'callback' => 'my_rest_function',
'permission_callback' => '__return_true',
'args' => array(
'number' => array(
'validate_callback' => function( $param, $request, $key ) {
return is_numeric( $param );
}
),
'offset' => array(
'validate_callback' => function( $param, $request, $key ) {
return is_numeric( $param );
}
),
'total' => array(
'validate_callback' => function( $param, $request, $key ) {
return is_numeric( $param );
}
),
),
) );
But, when I call it using for example:
https://example.com/wp-json/myplugin/v1/posts/?number=3&offset=0&total=3
I'm getting a No route was found matching the URL and request method.
error.
What am I doing wrong?