rest_attachment_query filter-hookWP 4.7.0

Filters WP_Query arguments when querying posts via the REST API.

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

This is one of the variants of the dynamic hook rest_(post_type)_query

Usage

add_filter( 'rest_attachment_query', 'wp_kama_rest_attachment_query_filter', 10, 2 );

/**
 * Function for `rest_attachment_query` filter-hook.
 * 
 * @param array           $args    Array of arguments for WP_Query.
 * @param WP_REST_Request $request The REST API request.
 *
 * @return array
 */
function wp_kama_rest_attachment_query_filter( $args, $request ){

	// filter...
	return $args;
}
$args(array)
Array of arguments for WP_Query.
$request(WP_REST_Request)
The REST API request.

Changelog

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

Where the hook is called

WP_REST_Posts_Controller::get_items()
rest_attachment_query
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 359
$args       = apply_filters( "rest_{$this->post_type}_query", $args, $request );

Where the hook is used in WordPress

Usage not found.