Filter Enhancements
Extras for the native Bricks query filters. Bricks stays the query engine: filters, indexes, AJAX and pagination are all Bricks. This plugin adds search inside long option lists, collapsible groups, a show-more limit, clear buttons, removable chips for the active filters, one-click presets, a mobile filter drawer, a toggle switch and saved searches. An opt-in advanced engine adds exact facet counts, nested AND, OR and NOT logic, price ranges with a histogram, repeater rows and a distance search.
Version: 1.3.0 · Requires: PHP 7.4+, WordPress 6.3+ and Bricks · Live demo
Installation
- Upload and activate the plugin.
- In Bricks, Settings, Query filters, switch query filters on.
- Open Settings, Bricks Filters and save your preferences.
- Add native Bricks filters and set each Target query as normal.
- Tell the plugin which filters to enhance in the configuration below.
- Optionally add the companion elements: Filter Enhancements, Toolbar, Presets and Boolean Toggle.
Enhancing a native filter
Add one entry for each filter, using the six-character ID from the filter’s class name (the part after brxe-). Paste the list into Filter configuration JSON:
[
{"id":"abc123","param":"destination","target":"xyz789","label":"Destination","search":true,"collapsible":true,"collapsed":false,"maxVisible":8},
{"id":"ghi789","target":"xyz789","resetId":"reset1"}
]
| Key | What it does |
|---|---|
id |
The Bricks filter element ID, without brxe-. |
param |
The filter’s URL parameter, so chips, presets and Clear know which values are yours. |
target |
The ID of the element that carries the query loop (not a CSS selector). |
label |
Name used for the chips and the search box. |
search |
A search box above the options. It appears when there are four or more. Overrides the global search setting for this filter only. |
collapsible, collapsed |
A Hide options button, and whether the group starts closed. |
maxVisible |
Show this many options, with a Show more button for the rest. |
clear |
Overrides the Clear buttons setting for this filter only: true shows a Clear button, false hides it. |
counts |
Overrides the selected-option counts setting for this filter only. |
resetId |
A native Bricks Reset element that the Clear filters button should press. |
Search, collapse and the show-more limit work on native checkbox and radio groups. Native select, search, range and date filters keep working exactly as Bricks built them.
Settings
Each of these is a tick box in Settings, Bricks Filters: enable enhancements, search inside option groups, clear buttons, selected-option counts, the mobile drawer, removable chips, keep position after updates, and console diagnostics for administrators. The page also holds the three JSON boxes (filters, presets and advanced schemas) and an optional list of search synonyms, one group per line, such as birds, avian, birdlife. Synonyms only help the search box find option labels.
Companion elements
- Toolbar: removable chips for what is selected, a Clear filters button, saved searches and a button that opens the filters in a drawer, popup or slide-down panel. While the drawer is in use the filters are not shown in the page: they live in the drawer, and the chips stay on the page so each one can be removed without reopening it. The real filter controls are moved, never copied, so Bricks keeps working.
- Presets: one-click named searches, shown as buttons or a dropdown.
- Boolean Toggle: a switch tied to the URL parameter of a native filter, for a yes or no choice such as Available only.
Drawer options
On the Toolbar element, with Filter drawer ticked:
- Style: over the page (a drawer or popup), or a slide-down panel that opens in the page under the toolbar and pushes the results down.
- Opens from: right, left, bottom (a sheet), top or centre (a popup).
- Animation: slide in, fade in or just appear, with a speed in milliseconds. Visitors who prefer reduced motion always get just appear.
- Width and height: any CSS length. Width applies to left, right and centre, height to top and bottom. Use 100% for full screen.
- Covers the page: yes and dimmed, yes but not dimmed, or no, so the page stays usable behind it. Page scrolling can be locked or allowed while it is open.
- Use at: phones (under 768px), tablets and phones (under 1024px), or every screen size. Above that size the filters stay in the page.
- Text: the button label, the heading and the bottom button (Show results by default).
- Which filters move: the filters listed in the filters box for that query. Anything else stays in the page.
The demo page shows the combinations, plus two real-life examples where the filters live in a popup or a slide-down panel and the chips stay above the results.
Presets
[
{"label":"Birds","target":"xyz789","params":{"category":"birds"}},
{"label":"Guides","target":"xyz789","params":{"category":"guides"}}
]
A preset opens the page with those parameters, and Bricks restores the filters from the URL. The values must be ones the matching native filter accepts.
Saved searches
Visitors can name and save the current filters. They are kept in that visitor’s own browser storage, not in an account, and they stop working if the browser blocks storage.
Advanced engine (opt-in)
Add one or more schemas under Advanced facet schemas JSON. A schema describes the post type and the facets to build, and lists the query loops it should filter:
[{
"id":"holidays",
"post_type":"holiday",
"targets":["abc123"],
"facets":{
"destination":{"type":"taxonomy","taxonomy":"destination"},
"price":{"type":"range","key":"lowest_price","histogram":true,"bins":12},
"leader":{"type":"meta","key":"trip_leader"},
"departure":{"type":"repeater","prefix":"departures","fields":{"year":0,"availability":1},"count_field":"year"},
"nearby":{"type":"geo","lat_key":"latitude","lng_key":"longitude"}
}
}]
| Facet type | URL value |
|---|---|
| taxonomy, meta | A comma-separated list: bfe_holidays_destination=africa,asia |
| range | Minimum and maximum: bfe_holidays_price=1000,3000 |
| repeater | Positional values that must match in one row: bfe_holidays_departure=2028,available |
| geo | Latitude, longitude and kilometres: bfe_holidays_nearby=51.5,-0.1,25 |
- Save the schema, then click Rebuild index beside it on the settings page. Rebuild again after changing a schema, repeater columns or after a large import. Saving, deleting and term and field changes update the index automatically.
- The listed query loops are narrowed by the URL values. When a control with a matching URL key changes, the plugin updates the address bar and asks Bricks to refresh the loop through its own native AJAX request, so the loop updates in place with no page reload, the same as a native filter. Native Bricks filters keep working alongside.
- Add controls with a matching URL key, or put
data-bfe-sync-param="bfe_holidays_destination"on a checkbox, select or input.
Nested logic
"expression":{"op":"AND","children":[
{"op":"OR","children":[{"facet":"destination"},{"facet":"leader"}]},
{"op":"NOT","children":[{"facet":"availability"}]},
{"facet":"price"}
]}
AND, OR and NOT nest up to 12 levels. A facet with nothing selected is skipped, and an empty group changes nothing.
Counts and the histogram
The public read-only endpoint /wp-json/bfe/v1/facets/holidays returns, for every facet, how many results each option would give with the other selections applied. Put the markup below on the page and the plugin fills in the numbers and disables options with no results:
<div data-bfe-facet="holidays:destination">
<label data-bfe-value="africa"><input type="checkbox"> Africa (<span data-bfe-count>0</span>)</label>
<span data-bfe-total></span>
</div>
The BFE, Histogram Range element draws the price bars and two sliders for a range facet with histogram on. The BFE, Geographic Radius element takes a place name and a distance in kilometres. It looks the place up with the public OpenStreetMap Nominatim service, once per click, and caches the answer for a week. Use a licensed geocoder on a busy site.
Updating several loops together
Loops that are not Bricks query loops can be refreshed another way. Wrap each region you want refreshed, including its query loop, in an element with a unique data-bfe-ajax-group value. Changing a control with data-bfe-sync-param then fetches the new page and swaps every region at once, with browser history. The plugin fires bfe:loops-updated afterwards, so any script that needs to restart can listen for it.
Security and privacy
Settings need the manage options capability and are sanitised, with a size limit on each JSON box. URL parameter names are limited to letters, numbers, dashes and underscores. The plugin makes no remote calls except the location lookup you trigger, and collects no personal data.
Known limits
- The advanced select and checkbox controls read their starting value from the URL, so a shared link opens in the right state.
- Option search filters the labels already on the page. It is not a server-side search.
- The advanced engine suits catalogues of a few thousand posts. Distance and repeater checks are capped at 3,000 posts, and counts refuse to guess above that.
- The counts endpoint is public. Do not expose private terms or field names through a schema.
- Mixing OR across different facet types is rejected rather than half-applied.
- Bricks scripts attached to a region swapped with
data-bfe-ajax-groupmay need restarting by your own code. Loops refreshed by Bricks itself restart their own scripts. - Presets, saved searches, Clear filters and the toggle tick and untick the real native inputs, so Bricks runs its own AJAX update with no page reload. Only if a configured filter cannot be found do they fall back to loading the page with the new URL.
Related plugins
See Nested Query for load more inside a terms loop, and Grouped Query List for headings over a query loop.