Skip Navigation

[Resolved] using conditional in 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.

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 9 replies, has 3 voices.

Last updated by edgarF-2 1 year, 9 months ago.

Assisted by: Waqar.

Author
Posts
#2583683
2023-03-30_15-08-18 Views issue.png

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

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
2023-04-07_17-35-01_2nd condsitional.png
2023-04-07_17-35-57_1st conditional.png
2023-04-07_17-34-1updated debug.png
2023-04-07_17-32-52_updated change.png

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

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

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

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