apply_filters( "rest_{$this->post_type}_query", array $args, WP_REST_Request $request )
- Since
- 4.7.0, 5.7.0
Filters WP_Query arguments when querying posts via the REST API.
Description
The dynamic portion of the hook name, $this->post_type, refers to the post type slug.
Possible hook names include:
rest_post_queryrest_page_queryrest_attachment_query
Enables adding extra arguments or setting defaults for a post collection request.
Compatibility
- WordPress
- since 5.7.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Parameters
$argsarray- Array of arguments for WP_Query.
$requestWP_REST_Request- The REST API request.
Where this hook fires · 1
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:444WP_REST_Posts_Controller::get_items()
Source code
* * @link https://developer.wordpress.org/reference/classes/wp_query/ * * @param array $args Array of arguments for WP_Query. * @param WP_REST_Request $request The REST API request. */ $args = apply_filters( "rest_{$this->post_type}_query", $args, $request ); if ( ! is_array( $args ) ) { $args = array(); } $query_args = $this->prepare_items_query( $args, $request ); $posts_query = new WP_Query();Changelog
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
5.7.0
Moved after the
tax_query query arg is generated.from the docblock4.7.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.