WP_REST_Pattern_Directory_Controller::get_collection_params(): array

In this article

Retrieves the search parameters for the block pattern’s collection.

Return

array Collection parameters.

Source

public function get_collection_params() {
	$query_params = parent::get_collection_params();

	$query_params['per_page']['default'] = 100;
	$query_params['search']['minLength'] = 1;
	$query_params['context']['default']  = 'view';

	$query_params['category'] = array(
		'description' => __( 'Limit results to those matching a category ID.' ),
		'type'        => 'integer',
		'minimum'     => 1,
	);

	$query_params['keyword'] = array(
		'description' => __( 'Limit results to those matching a keyword ID.' ),
		'type'        => 'integer',
		'minimum'     => 1,
	);

	$query_params['slug'] = array(
		'description' => __( 'Limit results to those matching a pattern (slug).' ),
		'type'        => 'array',
	);

	$query_params['offset'] = array(
		'description' => __( 'Offset the result set by a specific number of items.' ),
		'type'        => 'integer',
	);

	$query_params['order'] = array(
		'description' => __( 'Order sort attribute ascending or descending.' ),
		'type'        => 'string',
		'default'     => 'desc',
		'enum'        => array( 'asc', 'desc' ),
	);

	$query_params['orderby'] = array(
		'description' => __( 'Sort collection by post attribute.' ),
		'type'        => 'string',
		'default'     => 'date',
		'enum'        => array(
			'author',
			'date',
			'id',
			'include',
			'modified',
			'parent',
			'relevance',
			'slug',
			'include_slugs',
			'title',
			'favorite_count',
		),
	);

	/**
	 * Filter collection parameters for the block pattern directory controller.
	 *
	 * @since 5.8.0
	 *
	 * @param array $query_params JSON Schema-formatted collection parameters.
	 */
	return apply_filters( 'rest_pattern_directory_collection_params', $query_params );
}

Hooks

apply_filters( ‘rest_pattern_directory_collection_params’, array $query_params )

Filter collection parameters for the block pattern directory controller.

Changelog

VersionDescription
6.2.0Added 'per_page', 'page', 'offset', 'order', and 'orderby' to request.
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.