get_param() checks parameter sources in this priority order (from get_parameter_order()): JSON body > POST body > GET query string > URL route params > registered defaults. The first source that HAS the key wins — even if that source is less "authoritative" than you'd expect.
The gotcha: parameters captured by your route's regex (e.g. the id in '/wpdocs/v1/users/(?P\d+)') are checked SECOND TO LAST, after the query string. So a request to:
/wp-json/wpdocs/v1/users/5?id=999
...will have $request->get_param( 'id' ) return 999 (from the query string), NOT 5 (from the URL route). The same applies to a JSON body containing {"id": 999} sent to that same URL.
This matters if your code reads the same key in two different places and assumes they'll agree — for example, doing a permission check against $request->get_url_params()['id'] (or the URL structure itself) but then using $request->get_param( 'id' ) for the actual database operation. Since the two can diverge, this pattern can lead to acting on a different resource than the one that was permission-checked.
To avoid this, be explicit about which source you actually mean:
// Only trust what the route regex captured, ignore query/body entirely.
$id = $request->get_url_params()['id'] ?? null;
// Or, if you specifically want query-string input, be explicit:
$id = $request->get_query_params()['id'] ?? null;
Reserve get_param() for cases where you genuinely want "whichever source provides this key first," and use the specific getter (get_url_params(), get_query_params(), get_body_params(), get_json_params()) whenever the source matters — especially for any value used in a permission check or database query.
Retrieves a parameter from the request.
Parameters$keystringrequiredParameter name.
public function get_param( $key ) {
$order = $this->get_parameter_order();
foreach ( $order as $type ) {
// Determine if we have the parameter for this type.
if ( isset( $this->params[ $type ][ $key ] ) ) {
return $this->params[ $type ][ $key ];
}
}
return null;
}
View all references View on Trac View on GitHub
| Uses | Description |
|---|---|
WP_REST_Request::get_parameter_order()wp-includes/rest-api/class-wp-rest-request.php | Retrieves the parameter priority order. |
| Used by | Description |
|---|---|
WP_REST_Request::has_valid_params()wp-includes/rest-api/class-wp-rest-request.php | Checks whether this request is valid according to its attributes. |
WP_REST_Request::offsetGet()wp-includes/rest-api/class-wp-rest-request.php | Retrieves a parameter from the request. |
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |
get_param() checks parameter sources in this priority order (from get_parameter_order()): JSON body > POST body > GET query string > URL route params > registered defaults. The first source that HAS the key wins — even if that source is less “authoritative” than you’d expect.
The gotcha: parameters captured by your route’s regex (e.g. the id in ‘/wpdocs/v1/users/(?P\d+)’) are checked SECOND TO LAST, after the query string. So a request to:
/wp-json/wpdocs/v1/users/5?id=999
…will have $request->get_param( ‘id’ ) return 999 (from the query string), NOT 5 (from the URL route). The same applies to a JSON body containing {“id”: 999} sent to that same URL.
This matters if your code reads the same key in two different places and assumes they’ll agree — for example, doing a permission check against $request->get_url_params()[‘id’] (or the URL structure itself) but then using $request->get_param( ‘id’ ) for the actual database operation. Since the two can diverge, this pattern can lead to acting on a different resource than the one that was permission-checked.
To avoid this, be explicit about which source you actually mean:
// Only trust what the route regex captured, ignore query/body entirely.
$id = $request->get_url_params()[‘id’] ?? null;
// Or, if you specifically want query-string input, be explicit:
$id = $request->get_query_params()[‘id’] ?? null;
Reserve get_param() for cases where you genuinely want “whichever source provides this key first,” and use the specific getter (get_url_params(), get_query_params(), get_body_params(), get_json_params()) whenever the source matters — especially for any value used in a permission check or database query.
| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | Внутренние запросы к WordPress REST API | 0 | 8.19 | 08-08-2026 |
| 2 | Comment on WP_Icons_Registry by Rodrigo Vieira Eufrasio da Silva | 0 | 9.38 | 14-08-2026 |
| 3 | Comment on wp_insert_post by Rodrigo Vieira Eufrasio da Silva | 0 | 13.12 | 14-08-2026 |
| 4 | Comment on resolve_pattern_blocks() by Rodrigo Vieira Eufrasio da Silva | 0 | 10.65 | 14-08-2026 |
| 5 | Comment on load_script_textdomain_relative_path by Rodrigo Vieira Eufrasio da Silva | 0 | 8.69 | 14-08-2026 |
| 6 | Comment on load_script_module_textdomain() by Rodrigo Vieira Eufrasio da Silva | 0 | 6.98 | 14-08-2026 |
| 7 | Comment on wp_deregister_script() by Rodrigo Vieira Eufrasio da Silva | 0 | 29.53 | 14-08-2026 |
| 8 | WordPress REST API: Top Benefits for Web Developers | 0 | 12.37 | 18-08-2026 |
| 9 | PHP Type Juggling: как нестрогое сравнение превращается в обход аутентификации | 0 | 8.1 | 22-07-2026 |
| 10 | Add a JSON API to Any Static Site Generator | 0 | 6.83 | 23-04-2026 |