Skip Navigation

[Resolved] How to test for empty output from a View

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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by PaulS4783 1 year, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2506519

Please note that I AM NOT USING ToolSet BLOCKS ....
I repeat .. I AM NOT USING ToolSet BLOCKS.

I am using Views in LEGACY MODE in conjunction with Beaver Builder Themer templates.

My question:
I know that it is possible to use conditional statements to check for output from a TYPES custom field.

e.g.
[wpv-conditional if="( $(wpcf-message-to-students) ne '' )"]
<h3>⬛ Message to Students</h3>
<p>[types field='message-to-students'][/types]</p>
[/wpv-conditional]

BUT... what if I want to test whether the output from a View is empty, specifically the output from a View which produces the content of a repeatable field.

e.g.
<h3>⬛ Education</h3>
<p>[wpv-view name="faculty-education-repeating-field"]</p>

In our template, the above code will output the something like the following if repeatable field entries exist.

Education
2020 PhD Harvard
2016 MA Oxford
2012 BA Stanford

BUT ... if there is nothing in those repeatable fields, it will output like this:

Education
No items found

So this is undesirable.

HOW CAN I TEST WHETHER THE VIEW CONTAINS CONTENT VIA A CONDITIONAL STATEMENT OR SOME OTHER TECHNIQUE?

#2507157

Hi,

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

Here is a simple approach to show the view's output and the heading, only when it has some results.

1. You can wrap your view's output and the heading, inside a div container with a class name 'education-view-container':


<div class="education-view-container">

<h3>Education</h3>
[wpv-view name="faculty-education-repeating-field"]

</div>

2. Next, in place of the 'no items found' message (i.e. inside the [wpv-no-items-found]... [/wpv-no-items-found] tags), you can include the following CSS code, that hides this view's div container, whenever no results are returned:


<style> .education-view-container {display:none !important} </style>

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

regards,
Waqar

#2507807

That's brilliant!

Solved the problem perfectly.

Ticket closed.