| |

How to add FacetWP Reset Filters button

If you want to add a button to reset your FacetWP filters, you may use the snippet below:

Reset FacetWP Facets

Reset all facets:

FWP.reset();

Or reset one facet:

FWP.reset('make');

Or reset multiple facets:

FWP.reset(['make', 'model', 'year']);

Or reset individual values:

FWP.reset({ 'make': 'audi' });

Use onclick for buttons and other HTML elements:

<button value="Reset" onclick="FWP.reset()" class="facet-reset">Reset</button>

Don’t know where to write this code? check this FacetWP tutorial

Style your Facet Reset button

.facet-reset{
    font-size: 18px;
    font-weight: 500;
    padding: 4px 10px;
    line-height: 1.7em!important;
    background-color: #00b8bc; // add your own color code here
    color: #fff;
    border: 2px solid #00b8bc; // add your own color code here
    border-radius: 3px;
    -webkit-transition: all .2s;
    transition: all .2s;
    cursor: pointer;
}
.facet-reset:hover{
    color: #333;
    background-color: 009fa3; // add your own color code her
}

Show Reset button only when facets are selected

<script>
/*
Code placement: see the "Javascript" section on https://facetwp.com/how-to-use-hooks/

This assumes that your reset button looks like this:
<button value="Reset" onclick="FWP.reset()" class="facet-reset">Reset</button>
*/
(function($) {
    $(document).on('facetwp-loaded', function() {
        var query-string = FWP.build_query_string();
        if ( '' === query-string ) { // no facets are selected
            $('.facet-reset').hide();
        }
        else {
            $('.facet-reset').show();
        }
    });
})(jQuery);
</script>

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

4 Comments

  1. Thanks for this code, I used it successfully on my site!
    It doesn’t hide the button though, probably because I put the code in my `functions.php` instead of adding a code snippet plugin.

    Although I don’t mind this at all (it looks fine the way I’ve designed it), how can I get it to work?

  2. This code worked for me:
    (function($) {
    $(document).on(‘facetwp-loaded’, function() {
    var query_string = FWP.buildQueryString();
    if ( ” === query_string ) { // no facets are selected
    $(‘.facet-reset’).hide();
    }
    else {
    $(‘.facet-reset’).show();
    }
    });
    })(jQuery);