using conditional in view - Toolset (2025)

Author

Posts

#2583683

edgarF-2

Tell us what you are trying to do? I am trying to display a different output when no condition is true in previous view loop.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link

#2583903

Minesh

Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please clarify what conditions you want to apply and what content you want to display conditionally as well as share problem URL and tell me on what section you want to apply condition.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2585873

Minesh

Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is no else condition available.

I see on this page there is 3 items available with the conditional:
- hidden link

What exactly you want to display or what is your requirement I still do not get it. What condition you want to add or what exactly you want to display conditionally?

#2586139

edgarF-2

Hi

Sorry I thought I had explained better. I know you don't have if than else conditional. I stated that earlier. I said I am trying to mimic one in order to display ,on online ad instead of an empty page. This could just be a heading or anything conditionally. I tried checking for nothing being displayed by view and as you see that value is three like the loop count. I thought it would be empty or zero since nothing is displayed by the view. I then looked for a way to check the output from previous conditional an can't find anything in the list for short codes to check.
I hope this explanation is enough to get a resolution.

#2586539

Minesh

Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I understand - you have a section with heading and within the heading you are displaying the related content using the view.

What you want is if there is no item available to display with view, you also want to hide the heading as well. If this is correct then:

What you should do is, try to add a conditional block and configure it to check with view's shotcodes and further select "number of items found in view" and compare it as shown with the following image:
=> hidden link

Then move the conditional block between view's output and view's loop section as shown with the following image:
=> hidden link

And add whatever heading you want to display using heading block within the conditional block. The condition will check if there is any items to display then it will display the heading otherwise not.

#2589065

edgarF-2

The differance is I'm getting a return value from the View because I have a conditional to satisfy in the view. (1st and 2nd conditional images)

#2590247

Minesh

Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Do you mean you want to compare the current user role?

I'm not getting what exactly you want and what you want to compare using the conditional display.

#2590561

edgarF-2

If you can't understand what I've sent you, please pass this on to someone else.
This is not that difficult so if you have a language barrier or just can't see the obvious with all that I've sent you you need to pass this to someone else.

#2590897

Waqar

Hi,

Minesh has asked me to follow up on this ticket.

Reviewing through the existing messages and the current setup on your website, here are my recommendations:

The view 'Current Subscription' is set to show 'All Products' and then limit the results through a conditional block within the loop. As a result, the actual number of results that view brings in at the query level, differs from the number of items, shown on the front end.

To make use of the option 'Number of items found in Views' in the conditional block on the 'Subscriptions' page, our objective should be to limit/filter this view's results, at the query level and not through a conditional block within.

To achieve this you can add a new select type custom field with the 'Products' post type, named 'Allowed Roles', with options: 'Premium', 'Basic', and 'Subscriber'. Please make sure that the user role slugs and the option values of this field matches.

Through this custom field, you'll be able to filter/limit the results in the view 'Current Subscription', based on the current user role and this custom field value, using a custom function attached to the hook 'wpv_filter_query':
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
(without having a conditional block to match the product titles inside the loop)

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

regards,
Waqar

#2594337

edgarF-2

My issue is resolved now. Thank you! That is exactly what I asked to have clarified.

using conditional in view - Toolset (2025)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6105

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.