Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active July 20, 2021 15:32
Show Gist options
  • Save djrmom/fe96ec2a3eba6bcaec6e1f3ef9cdf390 to your computer and use it in GitHub Desktop.
Save djrmom/fe96ec2a3eba6bcaec6e1f3ef9cdf390 to your computer and use it in GitHub Desktop.
facetwp show/hide labels
<?php
add_action( 'wp_footer', function() {
?>
<script>
(function($) {
if ('object' !== typeof FWP) {
return;
}
$(function() {
FWP.hooks.addAction('facetwp/loaded', function() {
/* run code here after facetwp loaded, 100 below can be modified to set priority order */
$('.facetwp-facet').each(function() {
var facet_name = $(this).attr('data-name');
var facet_label = FWP.settings.labels[facet_name];
if ( 'undefined' !== typeof FWP.settings.num_choices[facet_name] && FWP.settings.num_choices[facet_name] > 0 && $('.facet-label[data-for="' + facet_name + '"]').length < 1 ) {
$(this).before('<h3 class="facet-label" data-for="' + facet_name + '">' + facet_label + '</h3>');
} else if ( 'undefined' !== typeof FWP.settings.num_choices[facet_name] && !FWP.settings.num_choices[facet_name] > 0 ) {
$('.facet-label[data-for="' + facet_name + '"]').remove();
}
});
}, 100 );
});
})(jQuery);
</script>
<?php
}, 100 );
@djrmom
Copy link
Author

djrmom commented Jul 20, 2021

Hi, please check https://facetwp.com/documentation/support/ for help with Facet. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment