Documentation / Filters & Filter Sets / Filter and options

Filter and options

By Filter we usually mean a filtering criterion, such as Brand, Color, Price, etc. However, in addition to the filtering criterion, a Filter also has a number of other properties, such as Title, View, Logic, Terms Sorting order, and so on.

On the WordPress dashboard side Filter is represented by a form with fields that allows you to define the filtering criterion and make all the settings for the Filter. On the front-end side, the Filter is one of the elements of the Filters widget, which usually displays all the terms and allows you to operate with them.

Example of a filter by color

Creating a Filter is very easy – on the edit screen of any Filter Set, you need to click “Add Filter” and you will see a new form with fields that define all the properties of the Filter.

Below are all the existing Filter options and their description. They can be divided into two groups: Basic, which are changed most often, and Advanced, which need to be accessed in specific cases and are hidden by default.

Basic Filter options

Option name Description
Filter by The criterion by which posts will be filtered. It can be Taxonomy, Custom Field, Post Author, or Post Date.
– Meta Key The name of the Custom Field by which posts will be filtered.
*appears only if you select one of the Custom Field Filters in the “Filter by” field.
– Taxonomy Defines the Taxonomy with numeric values, in order to create a range slider filter.
*appears only if you select Taxonomy Numeric in the “Filter by” field.
Filter Title Title of the filter that will be displayed in the Filters widget.
Prefix for URL This is a crucial parameter that defines the particular words or characters to be included in the URL for the corresponding filter.
View in Widget Defines which template to use in the Filters widget:
– Checkboxes
– Radio buttons
– Labels list
– Dropdown
– Numeric range (available for Custom Field Numeric and Taxonomy Numeric filters only)
– Date range (available for Post Date filter only)
– Show Term names Turns On or Off term names if a Filter with Color Swatches or Brand Images.
*appears only if you select in the “Filter by” field Taxonomy that has Color Swatches enabled.
– Date Type Defines the date type in the filter. Possible values are Date, Date Time, Time.
*appears only if you select Post Date in the “Filter by” field.

Advanced Filter options

These settings are available by clicking on the “More options” link in a Filter form.

More options link
“More options” link example
Option name Description
– Date Format Defines the date format that will be displayed in the Filters widget.
*appears only if you select Post Date in the “Filter by” field.
Filter Logic Defines the filter logic and behavior when visitor selects two or more terms of the same filter. Possible values are OR, AND.
OR – display posts that match any of the selected filter terms.
AND – display posts that simultaneously match all of the selected filter terms.
Sort Terms by Defines the criterion and order of sorting filter terms in the Filters widget.

– Default – the order of the terms corresponds to the order in which they were selected from the DataBase.
– Term name – sorts by term name
– Posts count – sorts by the number of posts in the term
– Term ID – sorts by term ID
– Menu order – sorts by manually defined order and is only available for WooCommerce attributes and Product Categories.

Include/Exclude Terms Defines which filter terms should be included or excluded from the Filters widget.
Folding If enabled, it makes the the Filter fold/unfold while clicking on it.
– Show Hierarchy Turns on the hierarchical view of terms in the Filters widget. The option is available only for taxonomies that have a hierarchy – parent and child terms, for example, Post Categories.
– Use for Variations If selected, filtering will consider this attribute value in variations instead of the attribute value in parent products. Only relevant for WooCommerce variable Products.
– Enable Range Slider? Turns On or Off the Range slider, which allows you to change the value of a numeric Filter by moving the slider instead of manually entering values into the Filter fields.
*only relevant for Numeric filters.
– Slider Step Defines the increment value when moving the range slider in a Numeric Filter. By default, it is set to 1.
*only relevant for Numeric filters.
Terms Search Turns On or Off a Search field in a Filter, which allows you to make live text search among filter terms.
Parent Filter Allows you to set the dependence of the terms of this filter on the selection of terms of another, parent filter.
If you specify a parent filter, the terms of this filter will not be shown until a parent term is selected.
– Hide until the Parent selected The whole child filter will be hidden until you select a Filter term from the parent filter.
Tooltip A short explanation you can write for the filter. It will appear next to the filter title as a question mark.
More/less Allows you to hide some of the terms under the toggle link to save space in the Filters widget. Useful in situations where the filter has too many terms.
Show in Chips Defines whether or not to show the selected filter terms in the Chips.

Prefix for URL

Prefix for URL is a Filter option that determines what kind of URL the filtering results page will have when filtered by this filter. For example, this is a filter by Color and you have specified the word color as the Prefix for URL. So the URLs of the filtering results pages will look something like this https://example.com/shop/color-blue/ or https://example.com/shop/color-yellow/ That is, the word color will be used in the URL of the page with the filter results.

You can specify any value in the Prefix for URL field, but it is important that it should not match to existing categories, tags, or post slugs, as this can cause conflicts and 404 errors on your site pages.

Use for Variations

“Use for Variations” – this option determines how to filter variable products – by the value of the attribute of the variations or by the value of the attribute of the parent product.

For example, this is a filter by Color and some variable (parent) product has a Blue color. But its variations have Blue, Green, and Red colors. If you disable the “Use for Variations” option for the color filter, then this product will be available only when you select the color “Blue” (i.e., as specified for the parent product). And if you enable this option, then this product will be available when you select any of the three colors – “Blue”, “Green”, or “Red” – because the filter will look for matches in the variations, not in the parent product.

So, using this option, you can define the filtering mode for variable products that suits you.

Parent filter

Parent filter – this option is useful in situations where filtering is performed step by step and the terms of one filter depend on the selection of terms of another. A popular and illustrative example is the situation with Car Brand and Car Model. The user usually selects the Brand first, for example, VolksWagen, and then a specific Model – Golf, Passat, or Tuareg. And when they have chosen VolksWagen, it makes no sense to show irrelevant models such as Land Cruiser, Camry, or Corolla in the Car Model filter, because they belong to a completely different Brand. Instead, it makes sense to display only those that match the selected Volkswagen Brand.

The Parent filter option was created for this and similar situations. In this example, for the Car Model filter, it is enough to specify the Car Brand filter as the Parent filter value, and then all models available in this filter will appear in it only after selecting a specific Brand. That is, it will be impossible to select a Model without first specifying a Brand.

Also, the “Hide until the Parent is selected” option allows you to completely hide this filter until some parent value is selected.

Multiple filters by the same criterion in one Filter Set.

Sometimes you may need to create two or more Filters based on the same criterion within a single Filter Set. Let’s say right away that this is technically impossible, but there are ways to solve this problem.

This need arises as a result of poor organization of the data structure. For example, when the same taxonomy is used for different purposes. Let’s imagine that you have a regular Post Category and you have divided its terms into two groups, Size and Color. You created the parent category Size and created the sizes S, M, L, XL, XXL and assigned them as child categories to the Size category. And for the Color category, you created and assigned White, Green, Blue, Black as children. And then you need to create two Filters – by Size and by Color – in one Filter Set and use the Include/Exclude option to specify the necessary terms for each of the Filters. Although technically, these are essentially two Filters by the same entity – the Post Category. Unfortunately, this is not possible for technical reasons, because a Filter Set can contain only one Filter by the same entity.

Two ways to solve the problem

If things haven’t gotten that far and you have the ability to create separate custom Size and Color taxonomies, as in our example above, without a lot of time and effort, then you should create them. This can be done, for example, with the CPTUI plugin or with program code. Otherwise, you will often have to divide your categories into separate groups – Size and Color – in many places on the site. When these are separate taxonomies, you will be able to work with them independently of each other and then it will obviously be easy for you to create two separate Filters within one Filter Set.

If things have gone too far and you cannot abandon this organization of taxonomy terms, or if changes will require a lot of time and effort, you can use a life hack – create two Filter Sets for the same page and insert the necessary Filters into each of them and configure the appropriate terms for them.

This life hack will allow you to use two different Filters by the same criterion on the same page, but this configuration will not be compatible with the “Pop-up Filters widget” option.

It is up to you to decide which way to solve this problem is best for you.

Sort terms by a Custom parameter

If none of the existing sorting options works for you, you can sort the terms using program code.
Here is an example of how to sort terms by the menu_order value of a term object.

/* Let's sort Color filter terms by the menu_order */
add_filter('wpc_terms_before_display', 'wpc_sort_terms_as_needed', 10, 2);
function wpc_sort_terms_as_needed($terms, $filter){
    // pa_color - is desired taxonomy
    if ($filter['e_name'] === 'pa_color') {
        $newTerms = [];
        foreach ($terms as $k => $term) {
            $termOrder = get_term_meta($term->term_id, 'order', true);
            $term->menu_order = ($termOrder !== false) ? $termOrder : 0;
            $newTerms[$k] = $term;
        }

        // To sort in descending order
        // usort( $newTerms, \FilterEverything\Filter\EntityManager::compareDesc('menu_order') );
        // To sort in ascending order
        usort($newTerms, \FilterEverything\Filter\EntityManager::compareAsc('menu_order'));

        return $newTerms;
    }

    return $terms;
}

Parameters

  • $terms (array) List of term objects
  • $filter (array) Current Filter parameters
  • $set (array) Filter Set fields with parameters
  • $urlManager (object) Of the UrlManager Class, that can be used to get the link to the filter

Make your filtering best with