Skip Navigation

[Resolved] Set a conditional to only show a view when items in view is not == 0

This support ticket is created 3 years, 9 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
- 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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by junev 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2206903
Screenshot 2021-10-27 at 13.26.11.png

Tell us what you are trying to do?

I'd like to set a conditional so that a block is shown when numbers of items found in a view is not equal 0.

Here are 2 examples for the section with the subheading "Downloads"

A) hidden link
has 1 item in the view (see Download)
B) hidden link
has 0 item in the view (see Download)

the block in the view template has the condition as seen in the screenshot, but the block shows up regardless.

If I leave the static value empty, the block will not be displayed in both.

What is the link to your site?
hidden link
hidden link

#2207665

Hi,

Thank you for contacting us and I'd be happy to assist.

The condition "Number of items found in Views" can be used inside the view block, whose number of result items, you'd like to evaluate. It can't be used independently, the way you're planning.

If your goal is to show the "Downloads" heading, only when the relevant view includes some results, you can move the heading's code in the view itself, between the "[wpv-items-found]" and "<!-- wpv-loop-start -->" tags. For example:


[wpv-items-found]
<h4>Downloads</h4>
<!-- wpv-loop-start -->

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2208595

Hi Waqar, your solutions is so elegant! Many thanks!