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{}
Hooks from the method
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 9.8.5
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 ); /** * Filters the active filter data provided by filter blocks. * * @since 11.7.0 * * @param array $filter_param_keys The active filters data * @param array $url_param_keys The query param parsed from the URL. * * @return array Active filters params. */ $filter_param_keys = array_unique( apply_filters( 'woocommerce_blocks_product_filters_param_keys', array(), array_keys( $url_query_params ) ) ); return array_filter( $url_query_params, function ( $key ) use ( $filter_param_keys ) { return in_array( $key, $filter_param_keys, true ); }, ARRAY_FILTER_USE_KEY ); }