The Toggle Post Filter is a frontend feature where visitors can toggle on/off tags and see a list of posts that match the search criteria. You can also add a text search field.
You can either use shortcodes or Gutenberg blocks. If you don’t feel comfortable with searching and configuring shortcode parameters, Gutenberg is the recommended path to follow.
For this tool you need to insert at least two blocks or shortcodes: One for the filter menu and one for the post block. Optionally you will also need one for the messages about how many posts were found and a reset button. Keeping these blocks separate makes it possible to freely arrange the components in your page layout.
Please make sure that you have published posts that use these tags that you see in the menu. If you still don’t see the posts, you may need to use the First Aid buttons in the Troubleshooting menu.
For all available options, see
- included taxonomies: Most sites show default WordPress posts. If you want to show products or gallery items or other post types, you will need to select the corresponding taxonomy here: product_tag, xyz_tag
- logical operator: Select here how matching posts should be determined from the tags.
- included groups: Narrow down the tag groups that should be used.
- text search: Optionally show a text search field. The search term will be connected with the other search criteria using the logical operator AND (refine the results). Search is triggered on pressing enter, optionally also after you stopped typing.
- caching: Speed up complex searches by caching the results on your server. You can also save the selected search criteria for each visitor with the “persistent filter” option. When they click through to a post and then return to the list, they continue where they left off.
- initially show all posts: This option lets you show all posts when no toggle is set, rather than showing an empty box with a placeholder message. This provides a “filter” experience, rather than searching.
- pager: Shows arrows at the bottom to load more or go back. Without a pager the rest of the list will be cut off. You can also set the number of posts per page.
- total amount: Optionally show a message about the total amount. You can use the extra block or shortcode for the message or display it in a an overlay (popup). This text can be customized for singular and plural.
- layout: There are two layouts for the menu part and six layouts for the post part. The menu can also be configured to hide tags in an accordion under each group. Hidden toggle switches are also effective.
- themes: Two out-of-the-box themes are available, dpf_toggle_menu_light and dpf_toggle_menu_dark. You set them in the div_class field of the menu and the body part.
- post template: It is recommended to edit the HTML for the posts in the Tag Groups settings (go to Front End, Post Filter). If you need different templates on your site, you can customize them here.
- Toggles or tags can be sorted by name, slug, ID, description or post count. For a custom order, you can add numbers in the tag description fields and then sort by description.
- Use include tags (terms) and exclude tags (terms) to fine-tune the available tags.
- With knowledge of CSS you can create your own themes. 1 Toggle switches are HTML checkboxes.
- This feature can only be used once on each page (including widgets), and it cannot be used together with the shortcode or block of the Dynamic Post Filter.
- If you sort posts randomly, you should disable the pager since for generating each page the total order of posts is randomized again.
Sometimes it comes in handy to preset tags for new visitors arriving at that page. Visitors will see the corresponding posts and can then change the filter.
There are two ways how to preset these initial tags: in the block/shortcode and via a URL parameter. In both cases you use the tag slug, which you find for each tag on the tags page. Multiple tags can be added in a comma-separated list.
In the Gutenberg block you select the tags in “Preset tags”.
In the shortcode for the menu part you enter:
Or you add the URL-Parameter to the URL of the page where you show the Toggle Post Filter:
If both the block/shortcode parameter and the URL parameter are set, we will use only the latter one.
Please note that preset tags are only effective when someone visits the page for the first time. When later returning to this page, some browsers keep the previous selection of toggles in the cache.
In the case that you also use the persistent filter (which is by default on – disable it with persistent_filter=0), the saved filter also takes priority over the preset tags. This means that visitors who made a selection and head over to a post will see their own selection when returning, rather than the preset tags. While you are testing you page, it might therefore help to temporarily disable the persistent filter or set it to a very low value.
If you preset a tag, it will be effective for all groups. It is not possible to turn on the toggle only in one group while the same tag would be off in another group.
Please note that it is unavoidable that complex queries take some time to process in the database. That is particularly the case if many tags are selected in multiple groups. It is therefore recommended to use caching (parameter caching_time, in minutes) to speed up queries that have appeared recently before.
The search, including tags and text, makes use of the default WordPress search functions, which are already optimized for use on busy websites.
If you don’t want your visitors to select tags with a toggle (on-off) switch but to enter them into a tag field, you could take a look at the Dynamic Post Filter.
If you don’t need the interactivity of a filter where posts respond live to search criteria, you may want to check out the Post List.
You can also use one of the tag clouds. They are highly customizable so that you can, for example, display all tags in the same size or prepend to each the same character. With the tag clouds, however, visitors don’t see immediately the list of matching posts. Instead, a click on the tag takes them to another page, where all posts are listed that use this tag.
If no tags or no posts appear, please make sure that
- you have selected the correct taxonomy. If you use something else than the default post_tag, use the taxonomy parameter.
- you have assigned your tags to groups
- use these tags in published posts (use the Meta Box).
If that still doesn’t help, you may want to try the buttons on the Troubleshooting page.
- The Toggle Post Filter in a classic layout with both themes
- The Toggle Post Filter with text search in a wide layout for the menu and a masonry layout for the posts
Further demos are available on this page.
- Unfortunately we are not able to help with customizations. Please consult your web designer. ↩