Skip Navigation

[Resolved] How to test 2 conditions using OR?

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

Problem: I would like to use a conditional to test if a numeric custom field value is empty or greater than zero. If so, I would like to display the value. If not, I would like to display nothing.

Solution: You could use "AND" in the comparison to test both ne '' and ne '0', like so:

{!{wpv-conditional if="( ($(wpcf-listing-price) ne '' ) AND ($(wpcf-listing-price) ne '0' ))"}!}PRICE: [types field='listing-price' format='FIELD_VALUE'][/types]{!{/wpv-conditional}!}

Or testing if the value is greater than zero might be a simpler solution:

{!{wpv-conditional if="( $(wpcf-listing-price) gt 0 )"}!}PRICE: [types field='listing-price' format='FIELD_VALUE'][/types]{!{/wpv-conditional}!}

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 4 years, 3 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 5 replies, has 3 voices.

Last updated by Amin 4 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1449423

Currently i'm using the code below to test for empty values in the Price field

{!{wpv-conditional if="( $(wpcf-listing-price) ne '' )"}!}PRICE: [types field='listing-price' format='FIELD_VALUE'][/types]{!{/wpv-conditional}!}

How can I test the field for empty values OR 0 (zero) as a value?

i.e. if wpcf-listing-price is NOT empty OR 0, then show something

#1449601

In this case, I think you should rewrite the conditional using AND -
i.e. (if wpcf-listing-price is NOT empty) AND (wpcf-listing-price is NOT 0)

{!{wpv-conditional if="( ($(wpcf-listing-price) ne '' ) AND ($(wpcf-listing-price) ne '0' ))"}!}PRICE: [types field='listing-price' format='FIELD_VALUE'][/types]{!{/wpv-conditional}!}

...or maybe if wpcf-listing-price > 0 would be simpler?

#1457947

HI Cristian. I'm going to try your solution and will get back to you shortly if I still need help.

Thanks!

#1458485

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Amin,

Christian, is currently out today but will be back tomorrow to continue to help you resolve this issue.

Thank,
Shane

#1467613

Standing by for your update.

#1470967

My issue is resolved now. I used the > 0 method and it worked perfectly. Thank you!

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