Skip Navigation

[Resolved] Conditional shortcode for view

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

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 5 years, 5 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 2 replies, has 2 voices.

Last updated by martinE-4 5 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#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: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00: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!