Skip Navigation

[Resolved] Problem with nested views – show empty term

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

Problem:

Hide the term items when their child posts view are empty.

Solution:

You can move the term information into child post view, for example:

https://toolset.com/forums/topic/problem-with-nested-views-show-empty-term/#post-1602323

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-attribute

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by David Gimenez 4 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1600943

Hi there.

I have a custom post type called wine. This custom post type has different terms
Tipus de vins: blanco, rosado, negro...
Llocs de consumicio: restaurant, domicili (in place or delivery)

I have a post view [wpv-view name="vista-de-vins-a-domicili"] that shows all posts filtered by:
Select posts with taxonomy: Tipus de vins set by the parent Taxonomy View AND Llocs de consumicio in all of these: Domicili

Taxonomy view that display tipus de vins [vista-de-tipus-de-vins-a-domicili], and are checked
Don't show empty terms
Include terms that have non-empty descendants
Include children in the post count

Loop item in Vista de tipus de vins a domicili -> I have
<h3>[wpv-taxonomy-title]</h3>
[wpv-view name="vista-de-vins-a-domicili"]

The problem is -> this view is showing terms with empty posts

I have wine rosé... but not all rose have the term "a domicili". In this case the view has no records, but if it have no records the term... why does it show in the view

This is the url where you can see the unexpected results of the view: hidden link

Thanks in advanced

#1602035

Hello,

I have checked the URL you mentioned above:
hidden link

There are two terms show result: "No items found":
- Vi Rosat
- Cava

How do you setup above two terms?

Are there sub-term under above two terms?
Are these two terms assigned with posts of other post types?

If there are sub terms under them, then you can edit the parent taxonomy view, disable option "Include terms that have non-empty descendants".

If these two terms are assinged with posts of other post types, then it is expected result, the condition "Don't show empty terms" is satisfied.

#1602239
Captura de pantalla 2020-04-27 a las 8.57.12.png
Captura de pantalla 2020-04-27 a las 8.58.19.png

Hi Luo and thanks you time. I answer below:

Are there sub-term under above two terms? No
Are these two terms assigned with posts of other post types?No... but llocs de consumicio YES. However... if i assign llocs de consumicio only to Vins... the result is the same

If there are sub terms under them, then you can edit the parent taxonomy view, disable option "Include terms that have non-empty descendants".There aren't subterms

If these two terms are assinged with posts of other post types, then it is expected result, the condition "Don't show empty terms" is satisfied. This terms aren't assigned with posts of other types. However... llocs de comsumicio is assigned to other 2 types of posts. If unassign this term to the other types of post the result is the same.

I attach 2 scrrenshots with the setup of my views.

Any idea?

Thanks again for your help.

#1602323

Thanks for the details, please check the screenshot you provided above:
https://toolset.com/wp-content/uploads/2020/04/1602239-Captura_de_pantalla_2020_04_27_a_las_8.58.19.png

There is another taxonomy filter:
Llocs de consumicio in all of these: Domicili

Have you tried to remove it and test again? It might conduct the problem you menitioned above, since the parent taxonomy view does not know the child posts are satisfied above taxonomy filter.

In my opinion, what you need is:
Hide the term items when their child posts view are empty.

If it is, you can try these:
1) Edit the parent taxonomy view, in section "Loop Editor", find and edit child post view's shortcode: [wpv-view name="vista-de-vins-a-domicili"]
pass term's title as shortcode attribute, for example:
[wpv-view name="vista-de-vins-a-domicili" term_title='[wpv-taxonomy-title]']

2) Edit the child post view "vista-de-vins-a-domicili", just after shortcode [wpv-items-found], display the term's title with shortcode:
[wpv-attribute name="term_title"]

More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-attribute
This shortcode displays the value of an attribute in a View shortcode.

#1602351

Hi again Luo.

Your suggestion works but not perfect. The title of empty taxonomies are not shown... but the message "no items found" is there. I don't know if a did all right.

Must I uncheck anything? Or just to delete the message in the output loop editor?

#1602357

Yes, you are right, you can just delete the message in the output loop editor.

#1602377

My issue is resolved now. Thank you!