Skip Navigation

[Resuelto] Coniditional output if/else

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
How to display conditional content based on custom field value empty or not empty

Solution:
You can use [wpv-conditional] shortcode in order to display the conditional content display.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/coniditional-output-if-else/#post-903743

Relevant Documentation:
https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/

This support ticket is created hace 5 años, 11 meses. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 respuestas, has 2 mensajes.

Last updated by Daniella hace 5 años, 11 meses.

Assisted by: Minesh.

Autor
Mensajes
#902618

I have tour operators that either have a twitter handle, a facebook ID or both. Here is my code:
[wpv-conditional if="( $(wpcf-twitter-handle) eq '' )" evaluate="false"]<img class="alignleft" src="hidden link field='twitter-handle' output='raw'][/types]/profile_image?size=bigger" />[/wpv-conditional]
[wpv-conditional if="( $(wpcf-facebook-id) ne '' ) OR ( $(wpcf-twitter-handle) ne '0' )" ]<img class="alignleft" src="hidden link field='facebook-id' output='raw'][/types]/picture?type=normal" />[/wpv-conditional]

This link, hidden link, only has a twitter handle, this one only has a fb ID, hidden link this one has both, hidden link. I need to show either one if it's available but hide the blank image placeholder if not as well as if a company has both then use the fb ID.
I can't seem to get the logic right.
Thanks for your help!

#902788

Minesh
Supporter

Languages: Inglés (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I think you are using wrong code:

Code to check if twitter handle is not empty - show it:

[wpv-conditional if="( $(wpcf-twitter-handle) ne '' )"]
<img class="alignleft" src="<em><u>hidden link</u></em> field='twitter-handle' output='raw'][/types]/profile_image?size=bigger" />
[/wpv-conditional]

Code to check if facebook ID is not empty - show it.

[wpv-conditional if="(  $(wpcf-facebook-id) ne '' )"]
<img class="alignleft" src="<em><u>hidden link</u></em> field='facebook-id' output='raw'][/types]/picture?type=normal" />
[/wpv-conditional]

Could you please try above code and try to resolve your issue.

#903125

Yes, the code I had worked, but now if a company has both twitter and facebook, it shows both:
hidden link
I only need it to show one. How can I do that?
Thanks!

#903571

Minesh
Supporter

Languages: Inglés (English )

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

Well - if company have both twitter and facebook - which Id you want to show?

Actually - what is your requirement?
- if both twitter and facebook available - show only one ID - which?
- if only twitter available - do we need to show it?
- If only facebook available - do we need to show it?

#903707

If both, then show Facebook.
If only Twitter, show Twitter. If only Facebook, show Facebook.

#903743

Minesh
Supporter

Languages: Inglés (English )

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

Well - could you please try following code and try to resolve your issue.

If both available, then show Facebook.

[wpv-conditional if="( $(wpcf-twitter-handle) ne '' ) AND ( $(wpcf-facebook-id) ne '' ) "]
<img class="alignleft" src="<em><u>hidden link</u></em> field='facebook-id' output='raw'][/types]/picture?type=normal" />
[/wpv-conditional]

If only Twitter, show Twitter.

[wpv-conditional if="( $(wpcf-twitter-handle) ne '' ) AND ( $(wpcf-facebook-id) eq '' ) "]
<img class="alignleft" src="<em><u>hidden link</u></em> field='twitter-handle' output='raw'][/types]/profile_image?size=bigger" />
[/wpv-conditional]

If only Facebook, show Facebook.

[wpv-conditional if="( $(wpcf-twitter-handle) eq '' ) AND ( $(wpcf-facebook-id) ne '' ) "]
<img class="alignleft" src="<em><u>hidden link</u></em> field='facebook-id' output='raw'][/types]/picture?type=normal" />
[/wpv-conditional]
#903745

That worked! Thank you so much!

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