Skip Navigation

[Resolved] conditional statement if shortcode value equals another shortcode value

This support ticket is created 2 years, 5 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 4 replies, has 3 voices.

Last updated by simchaH 2 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#2221657

Hello,

I am trying to figure out if I can compare the value of 2 shortcodes, and if they are equal to each other, then not to show it.

A bit more of an explanation of what I am trying to do:
I have a loop that is displaying the times for speeches in any given area. The way it is currently displayed is Mon: 7am Tue: 7am Wed: 7am and so on. I realize that the majority of speeches take place the same time each day for weekdays (mon-fri), so I am trying to consolidate if possible. I would like to compare the speech days shortcodes, i.e. if [speech-time-sunday] = [speech-time-monday], and so on, then hide that entire layout of the loop. I would then write an additional conditional statement saying that if they do equal each other, and have some code like this: Mon - Fri: 7am

Is it possible to configure the conditional shortcodes in such a way?
Thank You!

#2222073

Nigel
Supporter

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

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

Yes, the conditions on both the left and right of the comparison can be custom shortcodes (don't forget to register both at Toolset > Settings > Front-end content).

If you are using the block editor and the Conditional block, see the screenshot for an example.

If you are using the legacy editor and the conditional shortcode then the if attribute of the shortcode would be like so:

[wpv-conditional if=" ( '[first-shortcode ]' eq '[second-shortcode ]' )"]
...conditional content...
[/wpv-conditional]
#2222591

Thanks Nigel, that worked like a charm! I'm using the legacy editor and the conditional shortcode so you gave me the perfect syntax.

I was wondering if I would like to tie together all days of the week, so speech-time-monday eq speech-time-tuesday eq speech-time-wednesday, what's the correct syntax for that? I am assuming it is sticking in the AND operator I saw in the documentation, I just couldn't find an example there.

Also, how would I write up the syntax for "not equal"? Because if the shortcodes do not equal each other, then I will revert to the original line by line shortcode of Mon: 7am Tue: 8am Wed: 9am etc. so I would wrap all of that inside a not equals conditional statement.

Thanks so much Nigel, and thanks for your timely response!
Simcha

#2222937

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back and glad that Nigel's message helped.

We have a guide and examples for nesting and combining conditional statements at:
https://toolset.com/documentation/legacy-features/views-plugin/nesting-and-combining-conditions/

Here is the example of how your conditional statement will look like, to show some content only when all these days shortcodes, have the same value:


[wpv-conditional if=" ( '[speech-time-sunday]' eq '[speech-time-monday]' ) AND ( '[speech-time-monday]' eq '[speech-time-tuesday]' ) AND ( '[speech-time-tuesday]' eq '[speech-time-wednesday]' ) AND ( '[speech-time-wednesday]' eq '[speech-time-thursday]' ) AND ( '[speech-time-thursday]' eq '[speech-time-friday]' ) AND ( '[speech-time-friday]' eq '[speech-time-saturday]' ) "]
// show something when all the day values are the same
[/wpv-conditional]

For 'not equal' the operator is 'ne', and you'll find the introduction to the allowed operators in this guide:
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

To show some content, only when these days values are not the same, you can simply inverse the condition from the previous example, using the evaluate="false" attribute:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional )


[wpv-conditional if=" ( '[speech-time-sunday]' eq '[speech-time-monday]' ) AND ( '[speech-time-monday]' eq '[speech-time-tuesday]' ) AND ( '[speech-time-tuesday]' eq '[speech-time-wednesday]' ) AND ( '[speech-time-wednesday]' eq '[speech-time-thursday]' ) AND ( '[speech-time-thursday]' eq '[speech-time-friday]' ) AND ( '[speech-time-friday]' eq '[speech-time-saturday]' ) " evaluate="false"]
// show something when all the day values are not the same
[/wpv-conditional]

I hope this helps and please let me know if you need any further assistance around this.

#2223641

My issue is resolved now. Thank you!

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