Overview

FacetWP Dropdown facetThe dropdown facet type lets users select a single value.

Available options

Name Description
Data source Where the values live (taxonomy, custom field, post attribute). When choosing a hierarchical taxonomy, read this warning.
Default label Set the label for the first dropdown option (default: “Any”). Note: this label is translatable with the facetwp_i18n hook.
Parent term If Data Source is a hierarchical taxonomy and you want to display only child terms, enter the parent term’s ID.
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. If child options don’t show up, make sure the “Count” setting is high enough.
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.

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.

FacetWP Dropdown facet value modifiers

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 counts from all facets of a type that use a dropdown UI (all Dropdown facets, fSelect facets, Hierarchy Select facets, and Range List facets (in dropdown or fSelect UI mode)), add the following to your theme’s functions.php:

add_filter( 'facetwp_facet_dropdown_show_counts', '__return_false' );

If you want to hide counts from specific facets with a dropdown UI, then use this instead:

add_filter( 'facetwp_facet_dropdown_show_counts', function( $return, $params ) {
    if ( 'your_facet_name' == $params['facet']['name'] ) {
        $return = false;
    }
    return $return;
}, 10, 2 );

Hide dropdowns if one option is left

By interacting with facets, there will be situations when only one option (the ‘Any’ option) is left. With this code you can hide the dropdown when that happens:

<?php
    add_action( 'wp_head', function() { ?>
    <script>
      (function($) {
        $(document).on('facetwp-loaded', function() {
          $('.facetwp-type-dropdown select').each(function () {
            if ($(this).children('option').length == 1) {
              $(this).closest('.facetwp-type-dropdown').hide();
            } else {
              $(this).closest('.facetwp-type-dropdown').show();
            }
          });
        })
      })(jQuery);
    </script>
<?php } );

See also