X Features Cars Demo Power Plants Demo State Parks Demo Site Showcase Docs Tutorials Add-ons Buy

How to Hide Empty Facets

Using some JavaScript, you can hide facets that contain no values. In this example, each of our facets is contained within an element having the class of widget.

(function($) {
    $(document).on('facetwp-loaded', function() {
        $.each(FWP.settings.num_choices, function(key, val) {
            var $parent = $('.facetwp-facet-' + key).closest('.widget');
            (0 === val) ? $parent.hide() : $parent.show();

Place this code into your theme’s header.php or (better yet) into a custom javascript file.