Automattic\WooCommerce\Blocks\BlockTypes
ProductFilters::get_filter_params
Parse the filter parameters from the URL. For now we only get the global query params from the URL. In the future, we should get the query params based on $query_id.
Method of the class: ProductFilters{}
No Hooks.
Returns
Array. Parsed filter params.
Usage
// private - for code of main (parent) class only $result = $this->get_filter_params( $query_id );
- $query_id(int) (required)
- Query ID.
ProductFilters::get_filter_params() ProductFilters::get filter params code WC 10.8.1
private function get_filter_params( $query_id ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '';
$parsed_url = wp_parse_url( esc_url_raw( $request_uri ) );
if ( empty( $parsed_url['query'] ) ) {
return array();
}
parse_str( $parsed_url['query'], $url_query_params );
$filter_param_keys = wc_get_container()->get( Params::class )->get_param_keys();
return array_filter(
$url_query_params,
function ( $key ) use ( $filter_param_keys ) {
return in_array( $key, $filter_param_keys, true );
},
ARRAY_FILTER_USE_KEY
);
}