This document explains how to create custom filters for the Divi FilterGrid plugin. In most cases, the filters can be selected from within the module settings where you will find an easy-to-use interface allowing you to select which filters should be displayed. For more advanced cases, such as adding the module to a Divi Theme Builder archive template, we have provided a custom filter with examples below.
The custom filter is actually two filters: one to define the filters’ taxonomies and one for the filters’ terms. Both filters are required. You will also need to turn on the Use Custom Filters toggle in the Filter Options section of the module settings. This will bypass the filter options set in the module and will create filters based on the output of the custom filters as shown in the examples below.
The functions and filters below need to be added to your functions.php file located within your child theme.
In the example below, we are simply defining that our filter taxonomies will be comprised of both post categories and post tags:
You’ll want to replace category and post_tag with the taxonomies you would like to include. Here are some common options:
- product_cat (WooCommerce)
- product_tag (WooCommerce)
- download_category (Easy Digital Downloads)
- download_tag (Easy Digital Downloads)
In the filter below, we are defining two filters from our category and post_tag taxonomies from the taxonomies filter above: Category One and Tag One.
You’ll want to replace Category One and Tag One with the term names you would like displayed in the filters. You’ll also need to replace the term IDs 21 and 32 with the actual IDs of your terms. These can be found by logging into your WordPress site and going to the category or tag management page for your term. For posts, this would be the Posts -> Categories page. On this page you should see a list of terms. Hover over the term you would like to find the ID for. A long URL should appear in the bottom left of your screen. Find the number located after tag_id= in the URL. This is the ID of the term you are currently hovered on.
MultiLevel Terms Filters
The example below shows how you can display multiple levels of custom filters. You can still modify each level’s label from the module’s settings.
* The all filter text will be defined in the function above. If you want to display a level label or change the dropdown placeholder text, you can define that in the module’s settings in the MultiLevel Taxonomies field – https://youtu.be/UYA4HQMZJDA?t=229
Advanced Custom Filters
Again, in most cases the filters – like the ones created in the example above – can be defined right from within the module settings. A more likely scenario that would need the use of the custom filters would be Divi Theme Builder archive templates. Using a combination of our Custom Query and Custom Filters options, you can create dynamic results and filters based on the current archive page. Below we have provided more advanced examples like this that you can simply copy and paste into your functions.php file.