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!
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:
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
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]
[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.