WIP: Filters use empties the url_parameter values (for query strings)

Browser: Chromium Version 149.0.7827.114 & Firefox 151.0.3
Bricks Version: 2.3.7
OS: Linux Fedora
URL: Project is on-going developmene,t I can’t share publicly a url but I’ll describe the issue below

Hi,

For a vehicle rental website I am displaying the results of the available vehicles on a results page, using a query loop on my vehicle CPT.

Some query strings are passed onto that page:

  • date of departure
  • time of departure
  • date of return
  • time of return
  • a list of the vehicle codes that are available (which is determined beforehand through the search form)

The query loop only displays vehicles whose codes are within the vehicle code query string.

I added some filters on that page (sort by price, search for a vehicle name, checkboxes for some options, etc). The filters work great.

Now here’s the issue:

Every vehicle card has a button that leads to the booking funnel, the link is passing the query strings that are mentioned earlier:

When the result pages loads, I can see that all the links are working (e.g. https://mydomain.com/booking?date_depart=2026-06-18&date_return=2026-06-23 …)

But if I use any filter available (ticking a bow, sorting the results, etc), then the query strings values are empty, so clicking on the booking button will lead to the booking page with no query string value (e.g. https://mydomain.com/booking?date_depart=&date_return= …)

Is there something I’m doing wrong or forgot to do to ensure that my {url_parameter} values don’t reset when filters are enabled?

Thanks.

Hi @LouisC ,

Thanks for the detailed report.

This is currently a known limitation/bug with AJAX-rendered query results. On the initial page load, {url_parameter} can read the browser URL. But after using Query Filters, the loop/card HTML is rendered again through Bricks’ Query Filters API endpoint, so the original browser query string is not available in the same way.

We already have this tracked internally for AJAX query rendering, and I’ve linked your report to that task as another affected case. The expected fix would be for Bricks to pass the current browser URL parameters into the AJAX request so {url_parameter} can still resolve them after filtering.

By the way, I got a workaround for you here, maybe you can use it.

Query Filters mainly know about the selected filter values, stored in \Bricks\Query_Filters::$active_filters. If those values are Query Filter values, give the filters nice names like date_depart, date_return, etc., then build the booking URL with a small custom function:

function my_qf_value( $param, $query_id = '' ) {
	$param = sanitize_key( $param );

	if ( isset( $_GET[ $param ] ) ) {
		return my_qf_clean_value( wp_unslash( $_GET[ $param ] ) );
	}

	if ( class_exists( '\Bricks\Api' ) && \Bricks\Api::is_current_endpoint( 'query_result' ) ) {
		$query_id = $query_id ?: ( \Bricks\Api::$request_data['queryElementId'] ?? '' );

		foreach ( \Bricks\Query_Filters::$active_filters[ $query_id ] ?? [] as $filter ) {
			$url_param = $filter['url_param'] ?? '';

			if ( $url_param === $param ) {
				return my_qf_clean_value( $filter['value'] ?? '' );
			}
		}
	}

	return '';
}

function my_qf_clean_value( $value ) {
	if ( is_array( $value ) ) {
		return array_map( 'sanitize_text_field', $value );
	}

	return sanitize_text_field( $value );
}

function my_vehicle_booking_url() {
	$params = [];

	foreach ( [ 'date_depart', 'time_depart', 'date_return', 'time_return', 'vehicle_codes' ] as $key ) {
		$value = my_qf_value( $key );

		if ( $value !== '' && $value !== [] ) {
			$params[ $key ] = $value;
		}
	}

	return esc_url( add_query_arg( $params, home_url( '/booking/' ) ) );
}

Then use the function for the button URL, for example via an Echo dynamic tag:
{echo:my_vehicle_booking_url} (Whitelist my_vehicle_booking_url)

Regards,
Jenn

1 Like

Hey @itchycode thanks for the super fast answer :smiley:

Ok I see the problem, I tried your workaround but couldn’t make it work for now at least (I tried adding some radio filters sharing the url parameter than the one of the query strings I want to retrieve). If it’s supposed to work it’s probably that I missed something or didn’t set it up properly, I’ll ahve another go later today.