built-in facet type
Reset
Overview
The Reset facet type – added in FacetWP v4.0 – adds a reset button or link.
Depending on the settings, the button or link resets all facets or a selection only.
You can set the button or link to automatically hide when no facets have selected values.
Usage
Go to the Facets tab, click “add new”, choose “Reset” as Facet type, set its options, and place it on your page with a shortcode.
Available options
Name | Description |
---|---|
Reset UI | Should the facet show as a button or a link. |
Reset text | The text of the button or link. Note: this text is translatable with the facetwp_i18n hook. |
Include / exclude | Include or exclude certain facets:
|
Auto-hide | Automatically hide the reset button or link when no facets have selected values. |
Reset facets programmatically
Besides using a Reset facet, it is also possible to reset all, or specific facets and/or individual facet choices programmatically with the FWP.reset() function.
The facetwp/reset hook
The facetwp/reset
hook fires when a reset button/link is clicked. It could be used to select a specific facet choice after a reset, for example because a facet choice was pre-selected on page load:
// Replace "my_facet_name" with your facet name, and "my_facet_name" with the facet choice
add_action( 'wp_footer', function() { ?>
<script>
(function($) {
if ('object' !== typeof FWP) {
return;
}
$(function() {
FWP.hooks.addAction('facetwp/reset', function() {
FWP.facets['my_facet_name'] = ['my_facet_choice'];
});
});
})(jQuery)
</script>
<?php }, 100 );