Skip Navigation

[Assigned] I want to group results by taxonomy and count taxonomy items with >0 results

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.

This topic contains 7 replies, has 1 voice.

Last updated by ABSTRACTUS 14 hours, 32 minutes ago.

Assisted by: Christopher Amirian.

Author
Posts
#2846401
Bildschirmfoto 2026-02-04 um 12.32.28.png

At coworkingday.eu, we have a yearly event that is happening at many locations at the same day (a so-called "distributed event"). Locations can decide every year whether they want to join or not.

Hence we have "Locations" as a post type, with "Participation" (that includes the "year" field).
We also have "Country" as taxonomy.

E.g. for the map we are showing Participations, filtered by the year field, and render the map using the related Location's geoaddress fields. This works well.

Now we want to have a overview by country (taxonomy) [see attached concept screenshot]:
- For every country, the number of participating locations for the year 2026
- And the number of countries that have more than 0 (participating locations for the year 2026)

I somehow get stuck when I try to add the taxonomy as filter to the view of participations – it's not available in the filter dropdown? 🤔

Can you give me a hint how to get these different content forms into a filtered list?
Thank you!

#2846406

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Welcome to Toolset support. A View of “Participation” only offers filters for taxonomies assigned to Participation, not taxonomies assigned to the related Location (your “Country” taxonomy). So this is an expected behavior.

Maybe if you could do as follows:

- Create a View of “Locations” (not Participations) and filter it by having a related Participation where Year = 2026. This lets you keep the taxonomy (Country) on the queried post type (Location).

https://toolset.com/documentation/legacy-features/views-plugin/how-to-filter-by-related-posts/

- Create a Taxonomy View for “Country” terms, and nest the “Locations (Year=2026)” View inside each country term (filtered to the “current term”). That gives you “country → count of locations”.

https://toolset.com/documentation/legacy-features/views-plugin/using-a-child-view-in-a-taxonomy-view-layout/

- Inside the nested Locations View, output the count using [wpv-found-count] (place it inside [wpv-items-found] so it updates correctly).

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-found-count

- To show only countries with >0 locations, wrap the country block in [wpv-conditional] and check the nested View’s count.

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional

If you also need a single total number at the top, that typically requires either (a) a second Taxonomy View that excludes empty terms via the same conditional logic, or (b) a small custom function for aggregation.

I did not test the steps above, but it seems to be logical, that is why I suggested the steps.

Thanks.

#2846408

Thank you, yes this indeed seems to be logical.
However I already get stuck in step 1.

I don't get to filter the Locations by having a related Participation where Year = 2026

How to filter by parent I would know. But I don't get to filter by the Field of a Child?
I am really sorry I don't get there 🤔

#2846531

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Thank you. I think you are correct. Now I did a search and I found one of my colleagues mentioned that it is not possible via GUI:

https://toolset.com/forums/topic/use-custom-field-of-relationship-post-in-query-filter

Maybe it will be possible with wpv_filter_query. I can come up with a code that you can test. No gurantee but I will do my best.

So what I have in mind:

- Keep a Locations View, then use wpv_filter_query to restrict results to only Locations that have a related Participation where year = 2026.
- Add the snippet via Toolset → Settings → Custom Code.
- Use the Post Relationships API to query related posts:

https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

May I have the information below?

- Relationship slug (Location <> Participation)
- The meta key for the Participation year field.

Thanks.

#2846538

Thank you for the clarification!

The participation year field is: ecd-edition

The Relationship slug is more difficult, where do I find it? <ecd-participation> is a repeatable group in <location>, not a separate post type, hence the relationship is not in the Relationships list but a "built-in" relationship created by Toolset.

#2846572

Christopher Amirian
Supporter

Languages: English (English )

I see, so you do not have a relationship then and use repeatable group?

Maybe if you can set the next reply as private and give me the login information, I can check if you tell me where to look.

Thanks.

#2847201

Christopher Amirian
Supporter

Languages: English (English )

Ok thank you for the login information.

Let me see if I understand correctly:

You have locations Post type.

That post type contains a RFG called ECD Participation that includes a field called ecd-edition, which contains the Years.

What is needed:

A list of Taxonomies (Region or Region DE I am not sure which one)

And a number next to them.

The number should be calculated the number of locations inside that taxonomy that contains at least one participant entry with the entry of 2026.

My head spins 😀 Is it correct what I mentioned? Or I miss something here.

I doubt if it is possible to provide such a feature with UI. But first I need to make sure I understood the request.

#2847653

Thank you, yes this is absolutely correct.

It's the Region (not the Region DE)