Skip Navigation

[Resolved] Add taxonomy terms with post counts in filters and results

This thread is resolved. Here is a description of the problem and solution.

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 support ticket is created 3 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

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 franzG-4 3 years, 12 months ago.

Assisted by: Christian Cox.

Author
Posts
#1861897

Tell us what you are trying to do?
I want to have the post count per taxonomy. In the menu "Edit Taxonomy" there is a option "update_count_callback" to do this (counting the number of post per taxonmy name). This function is set to none (default). How to activate?
Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
Menu: hidden link

#1861905
Screen Shot 2020-11-30 at 1.54.06 PM.png

I want to have the post count per taxonomy.
Hello, WordPress automatically counts the number of posts associated with each taxonomy term - see the attachment here. The far right column includes a post count for each term.
- Is this what you want to display on the front-end of your site, or something else?
- Where do you want to display this information - in a View of posts showing each term for that post, in a term archive, or somewhere else?
- Are you using the Block editor to design this display, or the legacy Views editor?

#1862225
Screenshot view news example.jpg

Hello Christian,

many thanks for your reply. I am using the block editor for construction my views, and I woulk like to have the number of posts per category term in the FRONTEND, as it is the case in many blogs.

hidden link

that's my view with the filter in the left sidebar and the view on the page. I would like to have the number of posts for each taxonomy term in the filter as well as in the list of category terms follwing the posts excerpts in the view, like that: Food (12), s. also image in the annex with two examples (red numbers) (Branchen means industrial sector and the lists of terms are names of industrial sectors).

Is that possible?

Kind regards

Franz

#1862715
fields-and-text-html.png
filter-format.png

Okay thank you. Yes the post count can be shown with some adjustments in the Block Editor.

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.

#1862925

My issue is resolved now. Thank you!