Saltar navegación

[Resuelto] Conditional logic within shortcodes

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
- 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 -

Zona horaria del colaborador: Asia/Kolkata (GMT+05:30)

Este tema contiene 2 respuestas, tiene 1 mensaje.

Última actualización por hacerY 1 year, 3 months ago.

Asistido por: Minesh.

Autor
Mensajes
#2798256
Screenshot 2025-02-26 121346.jpg

Tell us what you are trying to do?
I am displaying a Type by using a shortcode. This is the HTML:
<p><i class="fas fa-map-marker-alt">[types field='city'][/types], [types field='state-or-province'][/types], [types field='country'][/types]</p>
Right now, if there is no value for [types field='city'][/types], it will still show a comma before the next field value. That is a bit weird, and I want to make that comma conditional. It should only follow [types field='city'][/types] if there is a value in there. If that value is empty, the comma should also not show.

I've tried to use the below HTML to achieve this, but it doesn't work, it still shows the commas even if the values are empty.

<p><i class="fas fa-map-marker-alt">
[wpv-conditional if="( '[types field='city' output='raw'][/types]' ne '' )"]
[types field='city'][/types]
[wpv-conditional if="( '[types field='state-or-province' output='raw'][/types]' ne '' )"], [/wpv-conditional]
[/wpv-conditional]

[wpv-conditional if="( '[types field='state-or-province' output='raw'][/types]' ne '' )"]
[types field='state-or-province'][/types]
[wpv-conditional if="( '[types field='country' output='raw'][/types]' ne '' )"], [/wpv-conditional]
[/wpv-conditional]

[types field='country'][/types]
</p>

Can you help me with this?

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional

Is there a similar example that we can see?
n/a

What is the link to your site?
enlace oculto

#2798431

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please try to use the following conditoinal shortcode and check if that help you to resolve your issue:

<p><i class="fas fa-map-marker-alt">[types field='city'][/types], [types field='state-or-province'][/types], [types field='country'][/types]</p>

[wpv-conditional if="( '[types field='city' output='raw'][/types]' ne '' )"]
[types field='city'][/types],
[/wpv-conditional]

[wpv-conditional if="( '[types field='state-or-province' output='raw'][/types]' ne '' )"]
[types field='state-or-province'][/types],
[/wpv-conditional]

[wpv-conditional if="( '[types field='country' output='raw'][/types]' ne '' )"]
[types field='country'][/types] 
[/wpv-conditional]
#2798480
Screenshot 2025-02-27 115623.jpg

Hello. Thanks for your reply. I've tried your suggestion, but it is still not resolved. I still see the redundant comma, and on top of that that information shows up twice now. Please see attached screenshot. I've changed it back to the original version for now. Do you have another suggestion that I can follow?

#2798486

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

That is strange. Can you please share problem URL and admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) 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.

#2799044

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I've enable the legacy view so we can build content template in legacy mode:
=> https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/

I've created the following content template and added the conditional code as given under:
=> enlace oculto

[wpv-conditional if="( '[types field='city' output='raw'][/types]' ne '' )"]<p><i class="fas fa-map-marker-alt"></i>[types field='city'][/types],[/wpv-conditional][wpv-conditional if="( '[types field='state-or-province' output='raw'][/types]' ne '' )"][types field='state-or-province'][/types],[/wpv-conditional][wpv-conditional if="( '[types field='country' output='raw'][/types]' ne '' )"][types field='country'][/types] [/wpv-conditional]</p>

I can see its working as expected:
- enlace oculto

#2799297

Thanks for your help! This is indeed working, also on the production site.