Faceted Filtering

Faceted search is the most useful and popular mode to filter catalogs of online retailers.

In Zephyr the Faceted Filtering is used by the List Filter element to improve UX while filtering lists of posts, pages, products, and custom post types. The main goal is to adapt the filtering options for the user's choice to the displayed result.

Advantages of the Faceted Filtering:

  • Filter values adapt to the Post List or Product List output
  • Filter values show amount of available posts
  • Filter values can be hidden if they are not available while filtering
  • Allows to filter taxonomies by Range Slider (currently doesn't work with negative and fractional values)
  • Allows to filter date sources by Range Slider (by years only)
  • Filters a list 10-50% faster (depending on the number of selected values)

Live example

How to enable the Faceted Filtering? #

  1. Open the List Filter "More options" settings tab, and enable the relevant "Faceted Filtering" switch, and save the changes.
  2. Open the settings of the related Post List or Product List element and enable the "Use URL params to show results" switch, and save the changes. This option is enabled by default if the list shows posts of the current query.
  3. Go to Theme Options > Advanced > Faceted Filtering section and click the "Index filter items" button. Once indexing is complete, your List Filter element will take all advantages of the Faceted Filtering.

What does indexing do? #

The WordPress database has different separate tables of posts attributes (dates, authors, taxonomy terms, custom fields, etc.). Therefore, counting the number of posts for each user selection creates heavy queries to the database. The more filtering parameters, the heavier the query, the longer the page loads.

That's why Zephyr creates its own database table for using by Faceted Filtering. When you start the indexing process, it:

  1. gets only used filter sources, based on the List Filter elements added to your site
  2. gets all published posts (of any post type), that have these sources
  3. populates the database table with combinations of all found posts and sources

That new table allows for faster calculation of the number of posts for each user selection.

When do I need to do indexing? #

  • When you add the new List Filter element with the enabled "Faceted Filtering" switch.
  • When you change the sources of any List Filter element with the enabled "Faceted Filtering" switch.

To avoid manual re-indexing when you create/edit/delete a post or a taxonomy term, just enable the "Automatic re-indexing" switch on Theme Options > Advanced > Faceted Filtering.

In case you change some posts programmatically (for example using a custom PHP export for product prices), you can use the PHP hooks us_filter_index_save_post and us_filter_index_delete_post that allows to index filter data by the provided post ID.

Filter Caching #

The faceted filter sends an AJAX request on every page load to display relevant results, without any visitor action. This can be noticed visually when the filter remains semitransparent (faded) for some time. If site traffic is high, it might result in a heavy server load, because AJAX requests cannot be cached by 3rd-party plugins or services.

Thats why we implemented the built-in caching for faceted filters.

Filter caching is not related to indexing of filter items. While indexing is necessary for filters to work correctly, caching only speeds up a filter loading (and reduces server load under high website traffic).

How to enable filter caching? #

At Theme Options > Advanced, under the Faceted Filtering section, activate the "Enable filter caching" switch and choose a desired cache lifetime.

How filter caching works #

When the non-logged-in user visits a page with a faceted filter, it creates a cached version of the filter' HTML code. The cache is saved into a separate database table named wp_us_filter_cache. All further visits of the same page will load the cached filter without AJAX requests. This can be noticed visually when the filter loads instantly.

Saved cache based on:

What is the optimal cache lifetime? #

It depends entirely on how often your filterable items (posts, products, CPTs) are edited (added, updated, deleted). The cache is only created by page visits and cannot be changed automatically (it can only be deleted and saved as new).

If you have e-commerce store with often catalog updates, you can select the "1 day" or less for the cache lifetime. If your site is rarely edited, you can select "1 month" or more for the cache lifetime.

Once the cache expires, it won't be deleted automatically. It will only be deleted when someone visits the page again.

In any case, you can always clear all cache manually by clicking the relevant button at Theme Options > Advanced.