Facet filtering is a type of search filter that allows users to narrow down their search results quickly while preventing zero results from being returned. The facets (or filters) dynamically adjust on the fly based on the user’s previous selections and provide visual feedback about the remaining options – view example.
The Filters add-on provides functionality for implementing a faceted search experience.
Getting Started
The initial setup for implementing Facets in Ajax Load More is easy – all it requires is a couple of settings to be configured in the Options section of a Filter.
Implementation Steps
Check the Enable Faceted Filtering option to activate facet functionality on the filter.
Select your target post types from the Post Types listing. Note: The Post Types selected should be the same post types that are being displayed in your main Ajax Load More listing.
Facets can be enabled on any new or existing Filter instance that uses supported field types and query parameters.
Once a facet has been enabled on a filter, Ajax Load More will handle the indexing and updating of the frontend display.
Result Counts
Display dynamically updating result counts for each facet selection by enabling the Result Count option in a filter group.
Note: Result counts are required to be enabled on each filter group individually.
The following field types are supported when using the faceted filtering in Ajax Load More.
Checkbox
Radio
Select
Select Multiple
Other field types, such as Star Rating and Range Slider will be supported in a future release.
Query Parameters
The following filter query parameters are supported when using the faceted filtering in Ajax Load More.
Taxonomy
Custom Fields
Tags
Tag__and
Category
Category__and
Post Type
Authors
Year
Month
Day
Filter Hooks
The following filter hooks are available when using facets functionality.
alm_filters_facets_index_{id}_args
This filter provides a method to modify the query args used for creating the facet index.
id: The unique filter ID.
add_filter('alm_filters_facets_index_movies_args',function($args){// Filter ID = movies$args['tax_query']=[['taxonomy'=>'actor','field'=>'slug','terms'=>'brad-pitt',]];return$args;},10,2);
PHP
Note: This hook is helpful for filter instances where the facet index doesn’t need to include all possible post IDs.
alm_filters_facets_transient_expiration
This filter provides a method to adjust the facet transient expiration time.
Below are common questions regarding Ajax Load More facets. If you have a question and don’t see an answer here, please visit the support page and submit your request.
Filters and facets often get mixed up because there’s so much overlap, however, both help to restrict a search to a subset of results.
Facets aid users in refining their search using several categories simultaneously. Faceting is still filtering but displays facets to allow users to choose from a set of useful values, features, and counts.
Filters provide basic options to help narrow down search results where the users don’t see the filter restrictions in place and may end up with zero results.
Facet data is stored in WordPress transients for up to 2 hours and is cleared when a post is published or edited. In this case, transients are used to avoid running expensive WP_Query lookups with every load more and filter action.
Each unique facet combination will contain a transient entry in your database prefixed with alm_facet_filter. The transient will contain an array of facet data that is used to update the available filter options on the frontend of the website.
The Facet index is an array of post IDs that are matched when a filter is changed or updated. Each Facet index is stored as an option in the wp_options table just as Ajax Load More filters are.
A facet index will be rebuilt when:
Resaving a filter.
Editing an existing post where the post type exists in the filter.
Clicking the Rebuild Facet Index button on the filter listing in the WordPress admin.