Skip Navigation

[Résolu] Conditional shortcode for view

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to output nothing from a View if there are no results?

Solution:
It's not necessary to use a conditional shortcode, you can simply remove everything in the wpv-no-items-found section of the View output.

If you have a heading or similar that you want to precede the View results and only show this when there are results to show, you can move the heading inside the View output section, within the wpv-items-found section but outside of the wpv-loop tags (otherwise it would be repeated for every result).

This support ticket is created Il y a 4 années et 10 mois. 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
- 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+01:00)

This topic contains 2 réponses, has 2 voix.

Last updated by martinE-4 Il y a 4 années et 10 mois.

Assisted by: Nigel.

Auteur
Publications
#1259045
Datastan_Meets_Storyland__Surfing_the_Zeitgeist_Without_Wiping_Out_–_ICASC_MIgration_1.jpg

I am trying to suppress a view and its heading (see image attached) if there are no items in the view.

I'm using a shortcode block in the Blocks plugin:
<b>Related Resources:</b><br>[wpv-view name="related-results-with-grid"]

I would like to wrap the whole thing in a wpv-conditional if to prevent it displaying if there are no items in the view.

The view is of a relationship (1-to-many) that shows child posts for the current post. (defined in Types)

#1259113

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

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

Hi Martin

To suppress the output of the View if there are no results you can simply edit the output section of the View and where you have the default No items found text within the wpv-no-items-found shortcode simply delete it so that nothing is output when there are no results.

Now, you could use a conditional shortcode to hide the heading when there are no results, but that would mean running the same query twice.

A better solution would be to simply move the heading inside your View to within wpv-items-found shortcode, immediately after the opening shortcode but outside the wpv-loop tags (so that it is not repeated).

#1261519

My issue is resolved now. Thank you!

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