Accueil › Toolset Professional Support › [Résolu] How to hide Taxonomy that has no related post
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
Marqué : Views, Views plugin
Ce sujet contient 4 réponses, a 2 voix.
Dernière mise à jour par Waqar Il y a 11 mois et 1 semaine.
Assisté par: Waqar.
I have 1 view showing a list of item Taxonomy items, and another view that shows list of posts that relate to the taxonomy items. I can't figure out how to hide taxonomy items that don't have related posts.
Specifically, I've created a custom post called Researches, and I've created two taxonomies for Researches; Grant Categories and Year Taxonomy
In one page, I want to show all the Researches that is of Grant Category: "Cluster Research Grant", grouped by Year Taxonomy: with output that is supposed to look like this:
2020
Adoption of Digital Technologies
Financing Schemes
2019
[some research title]
Problem now is that, the output also shows 2023, 2022, 2021 which does not have any related Research post associated which that taxonomy value. I cannot remove the 2023- 2021 years because I have Researches posts that have those years taxonomy but are Grant Category: "Small Research Grant"
I've reached the above stage by following this: https://toolset.com/forums/topic/how-can-i-group-views-by-custom-field/
This is the page I'm building now: lien caché
Thank you for sharing this update.
Can you please share temporary admin login details so that I can see how this view is set up in the admin area?
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
Thank you for sharing the access details.
The option 'Don't show empty terms' isn't enough in this case, because the nested post view ( 'Cluster Grant Researches by Year' ) is filtering by the 'Years Taxonomy' and the 'Grant Categories'.
To make this work, I added the following changes to the view 'Years group for Cluster Grant Researches':
1. I added a div container around each result of the taxonomy view so that the custom code can easily target each one:
( screenshot: lien caché )
.... <div class='year-tax-container year-tax-container-[wpv-taxonomy-slug]'> <h4>[wpv-taxonomy-slug]</h4> [wpv-view name="cluster-grant-researches-by-year" year-tax="[wpv-taxonomy-slug]"] </div> .....
2. In the same view's 'JS editor', I included the following custom script:
( screenshot: lien caché )
jQuery(document).ready(function( $ ) { $('.year-tax-container').each(function() { if($('a', this).length == 0) { $(this).remove(); } }); });
This code cycles through each container for the taxonomy results and removes the ones that don't have any link tag in them.
Wow... that works exactly as I wanted. Thank you very much for your help. I won't be able to come up with that solution myself.