Skip Navigation

[Resolved] Hide Empty Taxonomies

This support ticket is created 6 years, 2 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1097869

Tell us what you are trying to do?

I'm developing an album site with a 'Record Label' and 'Genre' Taxonomy. Using Views, I want to display the artists underneath their respective record labels, but only artists that also have the Genre taxonomy (that specific genre taxonomy being 'World Music').

So for example, I've managed to produce something like this:

===

Record Label #1

*Artist ABC
*Artist DEF
*Artist GHI

Record Label #2

No items found

Record Label #3

*Artist JKL

Record Label #4

No items found

====

When what I actually want is the above, but to also hide the Record Label entries that don't have the corresponding 'Genre>World Music' taxonomy. So this would display instead:

===

Record Label #1

*Artist ABC
*Artist DEF
*Artist GHI

Record Label #3

*Artist JKL

====

Notice Record Label #2 and #4 are 'hidden' as they don't have the second taxonomy (i.e the 'Genre' > 'World Music' taxonomy).

Is there any documentation that you are following?

I tried the following conditionals but no luck:
https://toolset.com/forums/topic/views-hide-if-taxonomy-is-empty/
https://toolset.com/forums/topic/new-custom-tax-not-displayed-in-layout-front-end-but-only-in-backend/

Is what I want to achieve possible, and if so, do you know how I can implement it? It feels like I'm nearly there, just need to figure out how to conditionally hide the 'empty' items.

Thanks

#1098404

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

You have a View to show Record Labels and a nested View to show Artists. The difficulty here is that you want to conditionally display the parent Record Label based upon properties of the child Artist (i.e. whether there are any with a particular genre).

You would need to write a custom function or shortcode that returned a count of the child artists that could be used in a conditional shortcode that determines whether to output the parent.

But, you can probably get away without that.

Instead of your outer View (that queries Record Labels) displaying the name of the Record Label, you display the parent Record Label in the child View.

After the [wpv-items-found] shortcode but before the wpv-loop tag, insert the post title using the Fields and Views button, and in the post selection tab specify that the source of the title should be not the current post but the parent Record Label post.

So that will only output the Record Label name if there are any corresponding Artist posts.

All that remains is to delete the "No items found" text from that same View so that if there are no Artist posts nothing at all will be output.

#1105391

Nigel, thank you for your response, it sounds like that could work. Just to clarify, do I only need one view and not two?:

---
"Instead of your outer View (that queries Record Labels) displaying the name of the Record Label, you display the parent Record Label in the child View.

After the [wpv-items-found] shortcode but before the wpv-loop tag, insert the post title using the Fields and Views button, and in the post selection tab specify that the source of the title should be not the current post but the parent Record Label post."
---

May thanks.

#1105460

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You still need both Views, but your parent View (that queries Record Labels) doesn't output anything itself.

In the Loop Output section of that View you insert the child View (to display Artists), but no fields from Record Label itself.

Edit the child View. If we are just talking about the title of the Record Label, after the wpv-items-found shortcode, but before the wpv-loop tag, use the Fields and Views button to insert the post title, and in the post selection tab specify that the title should come from the parent Record Label.

Remove the No items found text from the wpv-no-items-found section.

That should be all that's required.