WordPress: Hiding empty Facets (divs) if they contain no value

I am using the FacetWP plugin, which allows users to filter posts depending on certain parameters drawing from custom fields.

On their site, the plugin says you can hide empty facets using this code:

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

Facets on my site are wrapped in a div with the class “facetwp-facet” (see www.wgeil.de/listings/ for an example), so this should be targeting that div, in theory.

Could someone explain why this is not working? I have tried recreating the issue in JSFiddle but it worked there, so I am not sure what the problem is. To clarify, I am loading the above code into my theme header.

Read more here: WordPress: Hiding empty Facets (divs) if they contain no value

Leave a Reply

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