Skip Navigation

[Resolved] Conditional Shortcode Not Performing as Expected

This support ticket is created 5 years, 7 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Beda 5 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#1239383

I am not sure why the conditional shortcode below is not working correctly - it was generated by the types interface and not modified by me. It looks at a single checkbox custom field.

[wpv-conditional if="( $(wpcf-display-green-cta-button) eq '1' )" debug="true"]
Content Here
[/wpv-conditional]

Below is the debug code, which appears to match the number correctly, then not do at the converted expression stage.

####################
wpv-conditional attributes
####################
Array
(
    [if] => ( $(wpcf-display-green-cta-button) = '1' )
    [debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-display-green-cta-button) = '1' )
--------------------
After matching 1 numeric strings into real numbers: ( $(wpcf-display-green-cta-button) = 1 )
	Matched '1' to 1
--------------------
Converted expression: ( '' = 1 )
--------------------
#1239385

This is the condition generated by Toolset GUI when checking a Checkbox upon "is it equal 1":

[wpv-conditional if="( $(wpcf-checkbox) eq '1' )"][/wpv-conditional]

Hence your condition is correct.
And it works, at least, on my local install testing this.

1. My field is a checkbox field saving 1 as you see in the screenshot
2. I save a post with the Checkbox saved (checked) and in the Post Body check if it's saved with

[wpv-conditional if="( $(wpcf-checkbox) eq '1' )"]Yes it is checked[/wpv-conditional]

3. Viewing that post on the front end expectedly shows "Yes it is checked" when the box is checked, and nothing if not.

The debug results you show me I get ONLY if the checkbox is NOT checked in the backend, means, the condition obviously has to return "false" and not display anything.
If I check the box and save the post, then I get in the debug "Converted expression: ( 1 = 1 )", and hence, the condition shows it's contents

Given all this, my suspicion here is that the particular post you look at has the checkbox UNCHECKED in the backend.

If this is not the case, please send me a copy of that site https://toolset.com/faq/provide-supporters-copy-site/, so I can analyse it.