The Dynamic Post Filter

The Dynamic Post Filter is a tool for your pages where visitors can select groups and tags and immediately see posts that match their selection. It can be inserted into a page with the shortcode [[tag_groups_dpf]] or as a Gutenberg block. You can use it only once on each page.

Displaying Posts Filtered by Groups and Tags

Imagine you write posts about your travels and you tag these posts with the names of the countries. Now, you may want to assemble all those country tags under a tag group called “Countries”. Using the Dynamic Group Filter, your visitors can now open the group “Countries” and then select tags of your countries. The list of posts refreshes automatically and displays all posts that match one of the selected country tags.

Dynamic post filter with tags, WordPress
Example of the 2-layered Dynamic Post Filter: First select the group, then the tags.

 

 

For more options, see the list of parameters.

 

Performance

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 highly recommended to use the parameter caching_time (in minutes) to speed up queries that have appeared recently before.

If you choose to display the total amount of posts (parameter┬ádisplay_amount – from version 1.17) then this information needs to be retrieved through an additional database call (results are cached as well). You can avoid that if you set the parameter┬áposts_per_page=-1 (that means you display all posts) rather than an arbitrary high number (such as posts_per_page=100) because then we can simply count the elements in the list of posts.

 

Alternatives

If you don’t need the interactivity of the Dynamic Post Filter, or if you want to display all tags as clickable links, you can as well 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. Using the tag clouds, however, visitors don’t see immediately the list of matching posts. Instead, a click on the tag takes them to a “tag page”, where all posts are listed that have this tag.