wppaste
WordPress

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_query
  • rest_page_query
  • rest_attachment_query

Enables adding extra arguments or setting defaults for a post collection request.

Compatibility

WordPress
since 5.7.0
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3).

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 );		$query_args = $this->prepare_items_query( $args, $request ); 		$posts_query  = new WP_Query();		$query_result = $posts_query->query( $query_args ); 		// Allow access to all password protected posts if the context is edit.

Changelog

Introduced in 4.7.0. Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

Signature, return type and hooks compared across 5 parsed releases.

5.7.0
Moved after the tax_query query arg is generated.from the docblock
4.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.11 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.