Skip to content

Commit fd75dfa

Browse files
authored
Use correct query parameter name (#103)
1 parent a1ff708 commit fd75dfa

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

requests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ In the example above we see how path variables are stored as URL parameters in t
103103

104104
#### Query Params
105105

106-
Query parameters exist in the query string portion of a URI. The query string portion of a URI in `https://ourawesomesite.com/wp-json/my-namespace/v1/books?per_page=2&genre=fiction` is `?per_page=2&genre=fiction`. The query string is started by the '`?`' character, the different values within the query string are separated by the '`&`' character. We specified two parameters in our query string; `per_page` and `fiction`. In our endpoint we would want to grab only two books from the fiction genre. We could access those values in a callback like this: `$request['per_page']`, and `$request['genre']` ( assuming $request is the name of the argument we are using ). If you are familiar with PHP you have probably used query parameters in your web applications.
106+
Query parameters exist in the query string portion of a URI. The query string portion of a URI in `https://ourawesomesite.com/wp-json/my-namespace/v1/books?per_page=2&genre=fiction` is `?per_page=2&genre=fiction`. The query string is started by the '`?`' character, the different values within the query string are separated by the '`&`' character. We specified two parameters in our query string; `per_page` and `genre`. In our endpoint we would want to grab only two books from the fiction genre. We could access those values in a callback like this: `$request['per_page']`, and `$request['genre']` ( assuming $request is the name of the argument we are using ). If you are familiar with PHP you have probably used query parameters in your web applications.
107107

108108
In PHP, the query parameters get stored in the superglobal `$_GET`. It is important to note that you should never directly access any superglobals or server variables in your endpoints. It is always best to work with what is provided by the `WP_REST_Request` class. Another common method for passing in variables to an endpoint is to use body parameters.
109109

0 commit comments

Comments
 (0)