rest_<post_type>_collection_params

Filter collection parameters for the posts controller.

Description

apply_filters( 'rest_<post_type>_collection_params', (array) $query_params, (WP_Post_Type) $post_type ); 

The dynamic part of the filter $this->post_type refers to the post type slug for the controller.

This filter registers the collection parameter, but does not map the collection parameter to an internal WP_Query parameter. Use the 'rest__query' filter to set WP_Query parameters.

Parameters (2)

0. $query_params (array)
JSON Schema-formatted collection parameters.
1. $post_type (WP_Post_Type)
Post type object.

Usage

To run the hook, copy the example below.
  1. $query_params = apply_filters( 'rest_{$post_type}_collection_params', $query_params, $post_type ); 
  2.  
  3. if ( !empty( $query_params ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the rest_<post_type>_collection_params callback 
  2. function filter_rest_post_type_collection_params( $query_params, $post_type ) { 
  3. // make filter magic happen here... 
  4. return $query_params
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "rest_{$post_type}_collection_params", 'filter_rest_post_type_collection_params', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "rest_{$post_type}_collection_params", 'filter_rest_post_type_collection_params', 10, 2 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php  
  1. return apply_filters( "rest_{$this->post_type}_collection_params", $query_params, $post_type );