WordPress at a glance
function is not described

WP_REST_Attachments_Controller::prepare_items_query() protected WP 4.7.0

Determines the allowed query_vars for a get_items() response and prepares for WP_Query.

{} It's a method of the class: WP_REST_Attachments_Controller{}

No Hooks.

Return

Array. Array of query arguments.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_items_query( $prepared_args, $request );
$prepared_args(array)
Array of prepared arguments.
Default: empty array
$request(WP_REST_Request)
Request to prepare items for.
Default: null

Changelog

Since 4.7.0 Introduced.

Code of WP_REST_Attachments_Controller::prepare_items_query() WP 5.5.1

<?php
protected function prepare_items_query( $prepared_args = array(), $request = null ) {
	$query_args = parent::prepare_items_query( $prepared_args, $request );

	if ( empty( $query_args['post_status'] ) ) {
		$query_args['post_status'] = 'inherit';
	}

	$media_types = $this->get_media_types();

	if ( ! empty( $request['media_type'] ) && isset( $media_types[ $request['media_type'] ] ) ) {
		$query_args['post_mime_type'] = $media_types[ $request['media_type'] ];
	}

	if ( ! empty( $request['mime_type'] ) ) {
		$parts = explode( '/', $request['mime_type'] );
		if ( isset( $media_types[ $parts[0] ] ) && in_array( $request['mime_type'], $media_types[ $parts[0] ], true ) ) {
			$query_args['post_mime_type'] = $request['mime_type'];
		}
	}

	// Filter query clauses to include filenames.
	if ( isset( $query_args['s'] ) ) {
		add_filter( 'posts_clauses', '_filter_query_attachment_filenames' );
	}

	return $query_args;
}