WC_REST_Posts_Controller::get_collection_params PHP Method

get_collection_params() public method

Get the query params for collections of attachments.
public get_collection_params ( ) : array
return array
    public function get_collection_params()
    {
        $params = parent::get_collection_params();
        $params['context']['default'] = 'view';
        $params['after'] = array('description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), 'type' => 'string', 'format' => 'date-time', 'validate_callback' => 'rest_validate_request_arg');
        $params['before'] = array('description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), 'type' => 'string', 'format' => 'date-time', 'validate_callback' => 'rest_validate_request_arg');
        $params['exclude'] = array('description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), 'type' => 'array', 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list');
        $params['include'] = array('description' => __('Limit result set to specific ids.', 'woocommerce'), 'type' => 'array', 'default' => array(), 'sanitize_callback' => 'wp_parse_id_list');
        $params['offset'] = array('description' => __('Offset the result set by a specific number of items.', 'woocommerce'), 'type' => 'integer', 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg');
        $params['order'] = array('description' => __('Order sort attribute ascending or descending.', 'woocommerce'), 'type' => 'string', 'default' => 'desc', 'enum' => array('asc', 'desc'), 'validate_callback' => 'rest_validate_request_arg');
        $params['orderby'] = array('description' => __('Sort collection by object attribute.', 'woocommerce'), 'type' => 'string', 'default' => 'date', 'enum' => array('date', 'id', 'include', 'title', 'slug'), 'validate_callback' => 'rest_validate_request_arg');
        $post_type_obj = get_post_type_object($this->post_type);
        if (isset($post_type_obj->hierarchical) && $post_type_obj->hierarchical) {
            $params['parent'] = array('description' => __('Limit result set to those of particular parent IDs.', 'woocommerce'), 'type' => 'array', 'sanitize_callback' => 'wp_parse_id_list', 'default' => array());
            $params['parent_exclude'] = array('description' => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'), 'type' => 'array', 'sanitize_callback' => 'wp_parse_id_list', 'default' => array());
        }
        $params['filter'] = array('description' => __('Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce'));
        return $params;
    }

Usage Example

 /**
  * Get the query params for collections.
  *
  * @return array
  */
 public function get_collection_params()
 {
     $params = parent::get_collection_params();
     $params['status'] = array('default' => 'any', 'description' => __('Limit result set to orders assigned a specific status.', 'woocommerce'), 'type' => 'string', 'enum' => array_merge(array('any'), $this->get_order_statuses()), 'sanitize_callback' => 'sanitize_key', 'validate_callback' => 'rest_validate_request_arg');
     $params['customer'] = array('description' => __('Limit result set to orders assigned a specific customer.', 'woocommerce'), 'type' => 'integer', 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg');
     $params['product'] = array('description' => __('Limit result set to orders assigned a specific product.', 'woocommerce'), 'type' => 'integer', 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg');
     $params['dp'] = array('default' => 2, 'description' => __('Number of decimal points to use in each resource.', 'woocommerce'), 'type' => 'integer', 'sanitize_callback' => 'absint', 'validate_callback' => 'rest_validate_request_arg');
     return $params;
 }
All Usage Examples Of WC_REST_Posts_Controller::get_collection_params