Skip Navigation

[Resolved] Simple if else statement

This support ticket is created 5 years, 2 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Shane 5 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#1471421

Hi Toolset,

How can i make a simple if else statement with the conditional output?

I know there is a shortcode like this [wpv-conditional if="( $(wpcf-item-image-1) ne '' )"]Text here[/wpv-conditional] but i can't add a else statement here. I want to show wpcf-item-image-2 if wpcf-item-image-1 has no value.

Any idea how to solve this?

Thanks,
Menno

#1471799

Shane
Supporter

Languages: English (English )

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

Hi Menno,

Thank you for getting in touch.

Unfortunately there isn't any way to do an else statement with our Conditionals.

You will need to write an if statement for each condition that you want to check.

Thanks,
Shane

#1473179

Hi Shane,

But how can i do this with Toolset?

I have 2 image fields. Sometimes only field 1 has a value, but sometimes field 1 has no value and field 2 does have. In PHP it must be something like if field 1 has value > echo value field 1 elseif field 2 has value && field 1 has no value > echo value 2.

Thanks,
Menno

#1473201

Shane
Supporter

Languages: English (English )

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

Hi Menno,

Is your field a repeatable image field ? or is it a single image field.

If it isn't a repeatable field then you can just write 2 conditionals for each field to test the values

So to check if the field is not empty you would do this.

[wpv-conditional if="( $(wpcf-item-image-1) ne '' )"]Text here[/wpv-conditional]

If the field is empty you would do this.

[wpv-conditional if="( empty($(wpcf-item-image-1))) )"]This field is empty or does not exist[/wpv-conditional]

You will need to do this for each of your image fields and display the appropriate data based on the condition that is met.

Thanks,
Shane