Problem: I have built a custom search View in Blocks that displays several taxonomy term checkbox filters. The results include a list of taxonomy term archive links for each post. I would like to include a counter showing the number of posts for each term in both the filters and the results.
Solution:
1. To add the post count to the filter label, adjust the Format in Field Settings for the filter block. Edit this View in the Block Editor and select the taxonomy filter block. Then you will see configurations for Field Settings in the right column. In the Format field, insert the format:
%%NAME%% (%%COUNT%%)
See the attachment filter-format.png for an example.
2. To add the post count to each taxonomy term in the View results, you'll need a bit of code because the Block Editor does not provide similar formatting options for each taxonomy term displayed in a View. You may use a Toolset Fields and Text Block to insert the following code in the HTML tab:
<p>[wpv-post-taxonomy-iterator taxonomy="your-taxonomy-slug" field="views|shortcode|single|wpv-taxonomy-link" separator=", "][wpv-taxonomy-link] ([wpv-taxonomy-post-count])[/wpv-post-taxonomy-iterator]</p>
Replace your-taxonomy-slug in this code with the slug of the "Branchen" taxonomy. You can find the slug in Toolset > Taxonomies when you edit the taxonomy. See the attachment fields-and-text-html.png for an example in the Block Editor.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-taxonomy-iterator
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-taxonomy-link
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-taxonomy-post-count
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Our next available supporter will start replying to tickets in about 1.87 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 4 replies, has 2 voices.
Last updated by 3 years, 12 months ago.
Assisted by: Christian Cox.