Skip Navigation

[Resolved] Conditional output

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

Problem: If a View has results, I would like to display those results. If not, I would like to display a different View.

Solution: Use the "wpv-no-items-found" section of the Loop Output editor to display alternate information.

This support ticket is created 5 years, 4 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 louE 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1330461

Hello,

I have created conditional statements that work on my site. However, there is one that I am trying to create that is not working for me.

I have the following:

<div class="author_date">[wpv-view name="staff-view"] - [wpv-post-date]</div>
<div class="author_date">[wpv-view name="research-staff-view"] - [wpv-post-date]</div>

I need to show one if the other returns empty and vice versa.

Can the conditional statements look at the "name" of a view for data?

I'm at a loss here. Thank you.

#1330773

Hello, there are a couple of ways you could approach this.
1. You could use the "wpv-no-items-found" section of the View's Loop Editor to display alternate information when a View has no results. So you could place the research-staff-view View inside the wpv-no-items-found section of the staff-view View. This is probably the simplest approach.

2. You can use the PHP API to test the number of results for each View. We have an API called get_view_query_results:
https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results
You can use this API to get the number of results for a View. Then you could use this number in a conditional.

#1330915

Solution #1 worked for me. Thanks for the pointer. My issue is resolved now.