Hi @julian87,
Yes, it’s possible to preset the filter via query parameters, although the plugin doesn’t currently have a built-in option for this. At the moment this can be done with javascript to simulate clicks on the filter form.
Here’s a small jQuery snippet you can use as reference based on a ?tags= query parameter. It includes a short delay and a few retries to make sure the filter widgets are ready:
<script>
jQuery(function ($) {
var urlParams = new URLSearchParams(window.location.search);
var tagsParam = urlParams.get('tags'); // the URL parameter
var maxAttempts = 10;
var attempt = 0;
function tryClickTagCheckboxes() {
if (!tagsParam) return;
var values = tagsParam.split(',').map(function (v) {
return v.trim();
});
var success = false;
values.forEach(function (val) {
var $checkbox = $('.bpfwe-filter-item[name="tags"][value="' + val + '"]');
if ($checkbox.length && !$checkbox.prop('checked')) {
$checkbox.click(); // simulate user click
success = true;
}
});
if (!success && attempt < maxAttempts) {
attempt++;
setTimeout(tryClickTagCheckboxes, 200);
}
}
setTimeout(tryClickTagCheckboxes, 300);
});
</script>
With this, you can pre-filter your list by adding something like /?tags=shirts,red to the URL. The same approach can be adapted to other filters that require a click.
Let me know if this work for you or if you’d like a version with no hardcoded parameters.
Regards,
Dara
Thanks! I adapted the code a little bit and it works fine. But would be nice as a new feature for a future release to have a native filtering by query param.
Thanks for your great work and fast response!
Hi @julian87,
I’m glad the snippet worked for you and that you were able to adapt it to your needs. It is a feature I will consider adding in future releases.
Thanks again for your feedback and support.
Regards,
Dara