Skip Navigation

[Resolved] Nested views conditional logic

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

Problem: I have a nested View structure. If the inner View returns no results, I would like to hide the headline produced in the outer View.

Solution: Use a shortcode attribute to pass the current post ID into the nested View. Move the headline into the inner View's wpv-items-found section, and use the "item" attribute to target the parent post based on the shortcode attribute.

[wpv-view name="Future-events-same-band-inner" limit="4" offset="0" bandid="[wpv-post-id]"]
[wpv-layout-start]
[wpv-items-found]
<h1 class="future-event-same-band-headline">[wpml-string context="wpv-view" name="in event"]Предстоящи събития на [/wpml-string] [wpv-post-title output="sanitize" item="[wpv-attribute name='bandid']"]</h1>
<hr>
<!-- wpv-loop-start -->
<wpv-loop>
...

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

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

Last updated by NellyK1283 4 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1346209
attachment.png

Hello Toolset team,

I have a custom post type of gigs with detailed information about the music that will be played and the band that will be playing. I use nested views to display future events featuring the same band. Sometimes there might be more than one band at the event and I need to display separate lists of future events for each band.

Here is the parent view:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<h1 class="future-event-same-band-headline">[wpml-string context="wpv-view" name="in event"]Предстоящи събития на [/wpml-string] [wpv-post-title output="sanitize"]</h1>
<hr>
[wpv-view name="Future-events-same-band-inner" limit="4" offset="0"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-layout-end]

As you can see, the name of the nested view is Future-events-same-band-inner.

Generally, it works fine with just a little exception - I need to hide the title "Предстоящи събития на Национален филхармоничен хор ..." when there are no results. At the moment the title is visible no matter if there are any gigs to show. You can find a screenshot attached.

Please advise how to achieve it.
Thank you in advance for your help!

#1346701

I need to hide the title "Предстоящи събития на Национален филхармоничен хор ..." when there are no results
Hello, you could cut the h1 title from the parent View and paste it into the nested View "Future-events-same-band-inner". Use the item shortcode attribute in the shortcode to display the title of the post from the parent View, inside the nested View. Let me show you an example.

In the parent View you will pass the current post ID into the nested View using a shortcode attribute, like bandid:

[wpv-view name="Future-events-same-band-inner" limit="4" offset="0" bandid="[wpv-post-id]"]

Then in the Future-events-same-band-inner View, use the bandid attribute to display the title of the post from the parent View:

[wpv-layout-start]
[wpv-items-found]
<h1 class="future-event-same-band-headline">[wpml-string context="wpv-view" name="in event"]Предстоящи събития на [/wpml-string] [wpv-post-title output="sanitize" item="[wpv-attribute name='bandid']"]</h1>
<hr>
<!-- wpv-loop-start -->
<wpv-loop>
...

This technique called "passing arguments into Views" is described in more detail here:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

More information about the wpv-attribute shortcode here:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute

More information about the item attribute here:
https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/

Let me know if I have misunderstood the problem and I'll take a closer look.

#1346815

Fantastic, my issue is resolved now. Thank you, Christian!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.