Skip Navigation

[Resolved] Conditional logic not working in Views

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 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 3 voices.

Last updated by Minesh 9 months ago.

Assisted by: Minesh.

Author
Posts
#2691912

I am trying to: get conditional logic to work

Link to a page where the issue can be seen: hidden link

I expected to see: I expected to see links under the name of most of the artists

Instead, I got: Instead, it's showing me that the conditional logic is somehow not formatted correctly. I had been using this code successfully on another page, but I see now it's not working there either. Did something change in Toolset? This code should work:

[wpv-conditional if="( $(wpcf-facebook-link) ne '' ) AND ( $(wpcf-gallery-link) ne '' ) AND ( $(wpcf-instagram-link) ne '' ) AND ( $(wpcf-website-link) ne '' )" debug="true"]<h5 style="margin-top:0px;">Find [types field='first-name'][/types] online</h5>
[wpv-conditional if="( $(wpcf-website-link) ne '' )"][/wpv-conditional][wpv-conditional if="( $(wpcf-gallery-link) ne '' )"] [/wpv-conditional][wpv-conditional if="( $(wpcf-facebook-link) ne '' )"] [/wpv-conditional][wpv-conditional if="( $(wpcf-instagram-link) ne '' )"] [/wpv-conditional][/wpv-conditional]

#2692106

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Sorry for the slow response, we are having a busy spell.

I reformatted your markup to make it a little easier to see what it is supposed to be doing:

[wpv-conditional if="( $(wpcf-facebook-link) ne '' ) AND ( $(wpcf-gallery-link) ne '' ) AND ( $(wpcf-instagram-link) ne '' ) AND ( $(wpcf-website-link) ne '' )" debug="true"]
    <h5 style="margin-top:0px;">Find [types field='first-name'][/types] online</h5>
    [wpv-conditional if="( $(wpcf-website-link) ne '' )"]
        <a href="[types field='website-link' output='raw'][/types]" title="[types field='first-name'][/types]'s Website" target="_blank" style="margin-right:10px;" rel="noopener"><i class="fa-solid fa-desktop"></a>
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-gallery-link) ne '' )"]
        <a href="[types field='gallery-link' output='raw'][/types]" title="Gallery Website" target="_blank" style="margin-right:10px;" rel="noopener"><i class="fa-solid fa-palette"></a> 
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-facebook-link) ne '' )"]
        <a href="[types field='facebook-link' output='raw'][/types]" title="Follow [types field='first-name'][/types] on Facebook" target="_blank" style="margin-right:10px; margin-left:-4px;" rel="noopener"><i class="fa-brands fa-facebook"></a> 
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-instagram-link) ne '' )"]
        <a href="[types field='instagram-link' output='raw'][/types]" title="Follow [types field='first-name'][/types] on Instagram" target="_blank" style="margin-right:10px; margin-left:-4px;" rel="noopener"><i class="fa-brands fa-instagram"></a> 
    [/wpv-conditional]
[/wpv-conditional]

>it's showing me that the conditional logic is somehow not formatted correctly

What do you mean by that? What is it showing you?

You have an outer conditional shortcode which checks if **all* of the custom fields have values and will only output anything if they all do. Might it be that only some of the fields have values and therefore the test fails and nothing is output?

In which case you could change AND to OR.

#2692115

Hey there,

If you look at the link I sent you, you can see that it's showing the debug.

It's acting like none of the records have values in any of those fields, and that's false. Almost every record has at least one of those fields. For instance, here's the debug for one of them, showing clearly that several of the fields aren't empty, yet it's still not showing what I told it to show if they're not empty:

####################
wpv-conditional attributes
####################
Array
(
[if] => ( $(wpcf-facebook-link) ne '' ) AND ( $(wpcf-gallery-link) ne '' ) AND ( $(wpcf-instagram-link) ne '' ) AND ( $(wpcf-website-link) ne '' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-facebook-link) ne '' ) AND ( $(wpcf-gallery-link) ne '' ) AND ( $(wpcf-instagram-link) ne '' ) AND ( $(wpcf-website-link) ne '' )
--------------------
--------------------
Converted expression: ( '' ne '' ) AND ( '' ne '' ) AND ( 'hidden link' ne '' ) AND ( 'hidden link' ne '' )
--------------------

#2692197

Minesh
Supporter

Languages: English (English )

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

The converted expression you shared is following:

Converted expression: ( '' ne '' ) AND ( '' ne '' ) AND ( '
hidden link' ne '' ) AND ( 'hidden link' ne '' )

I see you are using AND clause so all conditional expression you added to conditional statement should satisfy and then and then it should display the result.

AS you can see the first expression:
- ( '' ne '' ) - this is false (AND)
- ( '' ne '' ) - this is false (AND)
- ( 'hidden link' ne '' ) - this is true (AND)
- ( 'hidden link' ne '' ) this is true (AND)

As you are using AND clause that means it will display the result only when all expression "true" but as you can see first two expression is false so it will not display the result.

Can you please check the values for your custom fields and make sure if all the fields has desired values added and then again compare the conditional statement.

#2692245

My code says that if any of those have a value, then print what I said to print. So, clearly two of them have values. Is there a different way to check to see if any of the fields have values?

#2692253

Minesh
Supporter

Languages: English (English )

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

if you want to check for any of the field values then you will have to apply OR clause.

What if you try to use the following code and check if that help you to resolve your issue:

[wpv-conditional if="( $(wpcf-facebook-link) ne '' ) OR ( $(wpcf-gallery-link) ne '' ) OR( $(wpcf-instagram-link) ne '' ) OR ( $(wpcf-website-link) ne '' )"]
    <h5 style="margin-top:0px;">Find [types field='first-name'][/types] online</h5>
    [wpv-conditional if="( $(wpcf-website-link) ne '' )"]
        <a href="[types field='website-link' output='raw'][/types]" title="[types field='first-name'][/types]'s Website" target="_blank" style="margin-right:10px;" rel="noopener"><i class="fa-solid fa-desktop"></a>
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-gallery-link) ne '' )"]
        <a href="[types field='gallery-link' output='raw'][/types]" title="Gallery Website" target="_blank" style="margin-right:10px;" rel="noopener"><i class="fa-solid fa-palette"></a> 
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-facebook-link) ne '' )"]
        <a href="[types field='facebook-link' output='raw'][/types]" title="Follow [types field='first-name'][/types] on Facebook" target="_blank" style="margin-right:10px; margin-left:-4px;" rel="noopener"><i class="fa-brands fa-facebook"></a> 
    [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-instagram-link) ne '' )"]
        <a href="[types field='instagram-link' output='raw'][/types]" title="Follow [types field='first-name'][/types] on Instagram" target="_blank" style="margin-right:10px; margin-left:-4px;" rel="noopener"><i class="fa-brands fa-instagram"></a> 
    [/wpv-conditional]
[/wpv-conditional]
#2692255

That worked, but what's weird is that the other code was working but then stopped. Thank you. I appreciate your time.