Saltar navegación

[Resuelto] Conditional Check Boxes

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

Problem:

I created a multi-checkbox custom field and used wpv-conditional to show links per choice, but only the first selection outputs even when multiple boxes are checked.

Solution:

Check each checkbox option individually using the Types shortcode with the option index and compare to "1"; update conditionals to [types field='psy-werbung' option='N'][/types] == "1" for each option.

Relevant Documentation:

https://toolset.com/forums/topic/conditional-display-if-option-from-multi-checkbox-is-checked/

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.

Este tema contiene 1 respuesta, tiene 1 mensaje.

Última actualización por Christopher Amirian 9 months ago.

Asistido por: Christopher Amirian.

Autor
Mensajes
#2826041

Tell us what you are trying to do?
I created a checkbox list as custom field in a CPT, now i would like to check the value of the checkboxes and return links depending on the selection.

Is there any documentation that you are following?
no
Is there a similar example that we can see?
no

here is the code i use in my content Template:
[wpv-conditional if="( $(wpcf-psy-werbung) eq '1' )"]
enlace oculto<hr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-psy-werbung) eq '2' )"]
enlace oculto<hr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-psy-werbung) eq '3' )"]
enlace oculto<hr>
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-psy-werbung) eq '4' )"]
enlace oculto<hr>
[/wpv-conditional]

Even if i check all checkboxes it only returns the first one.

#2826044

Christopher Amirian
Colaborador

Idiomas: Inglés (English )

Hi,

Welcome to Toolset support.

You’re comparing a multi-checkbox field as if it were a single value. Toolset checkboxes store multiple selections, so $(wpcf-psy-werbung) won’t match the way you expect. The supported way is to test each option individually and check whether it’s selected.

Use the Types shortcode with the option attribute; it returns "1" if that specific option is checked:

option="0" is the first option in the field definition
option="1" is the second, and so on

So your conditionals should look like this (adjust option indexes to match your field’s option order):

[wpv-conditional if="( '[types field='psy-werbung' option='0'][/types]' eq '1' )"]
Sunny Trips<hr>
[/wpv-conditional]

[wpv-conditional if="( '[types field='psy-werbung' option='1'][/types]' eq '1' )"]
Flixbus<hr>
[/wpv-conditional]

[wpv-conditional if="( '[types field='psy-werbung' option='2'][/types]' eq '1' )"]
Deutsche Bahn<hr>
[/wpv-conditional]

[wpv-conditional if="( '[types field='psy-werbung' option='3'][/types]' eq '1' )"]
Sunny Trips<hr>
[/wpv-conditional]

For more information:

https://toolset.com/forums/topic/conditional-display-if-option-from-multi-checkbox-is-checked/

Thanks.