Skip Navigation

[Resolved] Conditionnal statement

This support ticket is created 4 years 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.

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 13 replies, has 2 voices.

Last updated by ericK-4 4 years ago.

Assisted by: Nigel.

Author
Posts
#1558971

Hi,
In a view I want to display an error message when there's no advocate available in the search town. I make this :
<h1> Avocats dans cette ville</h1>
[wpv-view name="avocat-same-ville" currentcity="[types field='ville'][/types]"]
[wpv-conditional if="( $(wpcf-ville) eq '' )" evaluate="false"]
No advocate in this town !
[/wpv-conditional]

hidden link
When I type “Tourcoing” there's only one advocate. When I click to display the single under the sentence “Avocats dans cette ville”
The error message appears
But If I search an another town Roubaix for exemple, Toolset displays the advocate in the same town but the error message as well 🙁
Thanks for your help

#1559517

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

You don't really need a conditional shortcode for this, because you effectively have one built right into every View.

The output of each View has an "items found" section (your results) and a "no items found" section, for when there are no results.

Unless I have misunderstood what you are trying to do, I think you simply need to set the message in the no items found section of your View to "No advocate in this town!".

#1559609

Hi Nigel,

Yes I know. I add this conditional statement cause with this code toolset doesn't return the message :
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="avocat-container">
<wpv-loop>
[wpv-conditional if="( '[wpv-post-id item='@coordonnees.parent']' ne '[wpv-post-id item='$current_page']' )"]
[wpv-post-body view_template="loop-item-in-avocat-same-ville"]
[/wpv-conditional]
</wpv-loop>
</div>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No advocate in this town ![/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
Thnaks

#1560153

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

I can't tell what I'm looking at from that alone, you have post relationships involved here and I'm not sure what the Views are actually querying.

It's certainly the case that if a View returns no results it will display the text inside the no-items-found section, and if that is not being output it is because there are results to display, but then it looks like you might not be outputting those because you conditionally display the results.

Could I look at your site to see the set-up?

And could you explain what is being queried and what your conditional tests are aiming to achieve?

I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site.

#1560257

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Sorry Erick, it says the password is incorrect.

Could you please edit the last private reply and update if necessary?

#1562445

Hi Nigel,

I correct the password to access the backend
Best regards
Eric

#1562575

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Eric

I was able to enter your site, thank you.

It spent some time following the details to understand how this works.

In your View "Avocat same ville def" I've added a single line with my name to output the post title.

When you visit the link hidden link you can hopefully understand the problem.

That View always returns a result. You are using conditional shortcodes to hide the result if it is from the page we are currently looking at, but there will always be that result, so the no-items-found will never apply.

I think your solution would be to add another condition that checks if the result is the same as that of the current page (the opposite of your existing condition) and also checks wpv-found-count to see if there is only one result, in which case you will know that there are no other results for that town.

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-found-count

#1562915

Hi Nigel,
Thanks for your support. I put this line of code in my views without success that appears for me correct. but the sentence “No more advocate in this town" doesn't appear for Corinne Thulier
[wpv-conditional if="( '[wpv-found-count]' eq '0' )"]<p>No more advocate in this town </p>![/wpv-conditional]

#1563623

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

As I explained in the last reply the View always returns at least one result, so in the same way that wpv-no-items-found will never be output, wpv-found-count will never be zero, the minimum it can be (which you can treat as if it were zero) is one.

#1564463

Hi Nigel,

A bit lost and not so easy for me to understand. I try with this code without success as well
[wpv-conditional if="( '[wpv-found-count]' lt '1' )"]<p>No more advocate in this town !</p>[/wpv-conditional]

Eric

#1564571

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

It cannot be less than 1!

The way you have set this up the View "Avocat same ville def" will always return the post that we are currently looking at, e.g. the post hidden link will always return at least "thulier-corinne" as well as any other avocats added to Tourcoing.

It will never find no results because it will always find the avocat you are starting with, so the time to display "there are no other avocats in this region" is when there is precisely one result, not when there are no results (or less than one result, which is the same).

(It seems like you already knew this when you set up the View because you have a conditional shortcode to only show the output if the result isn't the same as the current avocat, which you obviously need to not duplicate the current avocat.)

#1564619

Hi Nigel

ok ! The solution is
[wpv-conditional if="( '[wpv-found-count]' lt '2' )"]<p>No more advocate in this town !</p>[/wpv-conditional]
Right ?

#1565191

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

That should be what you need, please try it and see.

If it's still not working let me know and I will try to add something myself.

#1565233

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.