Overview

FacetWP Checkboxes facetThe checkbox facet type lets users select multiple values.

Available options

Name Description
Data source Where the values live (taxonomy, custom field, post attribute). When choosing a hierarchical taxonomy, read this warning.
Parent term If Data Source is a hierarchical taxonomy and you want to display only child terms, enter the parent term’s ID. (Note: don’t use this in a multilingual setup, because the parent term IDs will be different for each language).
Value modifiers Enter a list of values (one per line) to include or exclude from the facet’s choices. The values need to match the label of the value exactly, including spaces and capitalization. If they don’t work, see this page for more info.
Hierarchical Whether to indent child terms. This option only appears if Data Source is a taxonomy. Note: the “Soft limit” option is not available in combination with ‘Hierarchical’. If child options don’t show up, make sure the “Count” setting is high enough.
Show expanded Should child terms be visible by default?
Show ghosts Show choices that would return zero results?
Preserve ghost order Keep ghost choices in the same order (mixed with valid choices)?
Facet logic Assume a facet with the choices “Apple”, “Banana”, and “Pear”.

  • AND (match all) – if selecting “Apple”, the choices “Banana” and “Pear” will disappear.
  • OR (match any) – if selecting “Apple”, the choices “Banana” and “Pear” will remain. If you select both “Apple” and “Banana”, results matching EITHER will remain.
Sort by Sort facet choices by:

  • Highest count – sorts by the total number of results with that value.
  • Display value – sorts alphabetically according to the label you see on the facet choices.
  • Raw value – sorts by the value that tracks the facet choices. For example in a dropdown, this is the option value rather than the option label. You can see the raw values in the url after making facet selections.
  • Term order – sorts by taxonomy term order. This option uses term_order which is only available when using a plugin that sets an explicit order for taxonomy terms. FacetWP supports:
Count The number of options to display. Be aware that if your source is a hierarchical taxonomy, the count includes the child terms/categories. If the count is too low, (some) child options will not show up.
Soft limit The number of options before showing the “See more” link. Set to 0 to display all options. Note: the ‘Soft limit’ option is not available in combination with ‘Hierarchical‘.

What are ghosts?

Ghosts are facet choices that do appear in the unfiltered results — but disappear after being filtered out. If a facet choice has no associated content, then it will never appear.

What are value modifiers?

Value modifiers let you include or exclude certain choices from displaying. This setting requires a re-index to take effect. Below are some examples.

The values you enter in a facet’s “Value modifiers” field need to match the label of the value exactly, including spaces and capitalization. If they don’t work, see this page for more info.

Hide counts

To hide the counts for all facets of type Checkboxes, Radio, Hierarchy, and Range List (in UI modes “None”, “Radio” or “Checkboxes”), add this CSS into your theme’s style.css:

.facetwp-counter {
    display: none;
}

If you need to be specific about which (type of) facet to hide the counts for, use any of the following styles:

/* Hide counts in all facets with a checkboxes UI (Checkboxes facet, Range List facet in UI mode "Checkboxes" */
.facetwp-checkbox .facetwp-counter {
    display: none;
}

/* Hide counts in all Checkboxes facets */
[data-type="checkboxes"] .facetwp-counter {
    display: none;
}

/* Hide counts in a specific Checkboxes facet */
.facetwp-facet-yourfacetname .facetwp-counter {
    display: none;
}

Automatically expand checked hierarchical checkboxes

In a hierarchical checkbox facet, when a child item is selected, the parent will expand automatically.
If you also want to automatically expand the parent if it is selected itself, use this code:

<?php
  add_action( 'wp_footer', function() {
  ?>
    <script type="text/javascript">
      (function($) {
        document.addEventListener("facetwp-loaded", function() {
          $(".facetwp-checkbox.checked .facetwp-expand").trigger("click");
        });
      })(jQuery)
    </script>
  <?php
}, 100 );

Customize the expand- and collapse buttons

This is a code example that replaces the expand- and collapse buttons with text:

add_filter( 'facetwp_assets', function( $assets ) {
    FWP()->display->json['expand'] = '<span>expand</span>';
    FWP()->display->json['collapse'] = '<span>collapse</span>';
    return $assets;
});

See also