WP_REST_Search_Controller::get_collection_params()publicWP 5.0.0

Retrieves the query params for the search results collection.

Method of the class: WP_REST_Search_Controller{}

No Hooks.

Return

Array. Collection parameters.

Usage

$WP_REST_Search_Controller = new WP_REST_Search_Controller();
$WP_REST_Search_Controller->get_collection_params();

Changelog

Since 5.0.0 Introduced.

WP_REST_Search_Controller::get_collection_params() code WP 6.6.2

public function get_collection_params() {
	$types    = array();
	$subtypes = array();

	foreach ( $this->search_handlers as $search_handler ) {
		$types[]  = $search_handler->get_type();
		$subtypes = array_merge( $subtypes, $search_handler->get_subtypes() );
	}

	$types    = array_unique( $types );
	$subtypes = array_unique( $subtypes );

	$query_params = parent::get_collection_params();

	$query_params['context']['default'] = 'view';

	$query_params[ self::PROP_TYPE ] = array(
		'default'     => $types[0],
		'description' => __( 'Limit results to items of an object type.' ),
		'type'        => 'string',
		'enum'        => $types,
	);

	$query_params[ self::PROP_SUBTYPE ] = array(
		'default'           => self::TYPE_ANY,
		'description'       => __( 'Limit results to items of one or more object subtypes.' ),
		'type'              => 'array',
		'items'             => array(
			'enum' => array_merge( $subtypes, array( self::TYPE_ANY ) ),
			'type' => 'string',
		),
		'sanitize_callback' => array( $this, 'sanitize_subtypes' ),
	);

	$query_params['exclude'] = array(
		'description' => __( 'Ensure result set excludes specific IDs.' ),
		'type'        => 'array',
		'items'       => array(
			'type' => 'integer',
		),
		'default'     => array(),
	);

	$query_params['include'] = array(
		'description' => __( 'Limit result set to specific IDs.' ),
		'type'        => 'array',
		'items'       => array(
			'type' => 'integer',
		),
		'default'     => array(),
	);

	return $query_params;
}