1

I want the UID parameter of this REST route I'm registering to accept both a single value or multiple values (let's say a comma-separated list, like "800,300,100").

Is there some standard way to do it, or should I take the whole string and manage the commas on my own? Looking around, I find only single-value code samples.

  register_rest_route('my-api/', 'subscribe/course-id/(?P<cid>\d+)/user-id/(?P<uid>\w+)', array(
        'methods' => 'GET',
        'callback' => 'my-callback',
    ));
  • A strong with commas is a single value, and would be registered as a single parameter. Splitting it and interpreting it as multiple value is something to need to handle yourself in your callback (and document, if necessary). – Jacob Peattie Oct 21 at 8:45
  • Got it. I'll change \w+ to [a-zA-Z0-9_,]+ so that it recognizes the comma – CharlesM Oct 21 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.