Skip Navigation

[Resolved] A conditional tag within a shortcode

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have a shortcode that I want to use conditionals inside the attributes but it is not rendering well.

Solution:

Register the shortcode in Toolset:

https://toolset.com/documentation/legacy-features/views-plugin/shortcodes-within-shortcodes/

Create a custom shortcode which will contain the result of the conditionals to avid any character mix up and rendering issues:

https://toolset.com/documentation/programmer-reference/adding-custom-code/how-to-create-a-custom-shortcode/

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.

This topic contains 2 replies, has 2 voices.

Last updated by kyleH-6 1 year, 11 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2609095

I'm trying to conditionally show a field within a shortcode:

[bgc_generate_chart year="[types field='year-of-birth' output='raw'][/types]" month="[types field='month-of-birth' output='raw'][/types]" day="CODE BELOW SHOULD GO HERE" hour="[types field='hour-of-birth' output='raw'][/types]" minutes="[types field='minutes-of-birth' output='raw'][/types]" timezone="Europe/London"]

[wpv-conditional if="( $(wpcf-month-of-birth) eq '02' )"][types field='day-of-birth-29' output='raw'][/types][/wpv-conditional]
[wpv-conditional if="( $(wpcf-month-of-birth) eq '01' ) OR ( $(wpcf-month-of-birth) eq '03' ) OR ( $(wpcf-month-of-birth) eq '05' ) OR ( $(wpcf-month-of-birth) eq '07' ) OR ( $(wpcf-month-of-birth) eq '08' ) OR ( $(wpcf-month-of-birth) eq '10' ) OR ( $(wpcf-month-of-birth) eq '12' )"][types field='day-of-birth-31' output='raw'][/types][/wpv-conditional]
[wpv-conditional if="( $(wpcf-month-of-birth) eq '03' ) OR ( $(wpcf-month-of-birth) eq '06' ) OR ( $(wpcf-month-of-birth) eq '09' ) OR ( $(wpcf-month-of-birth) eq '11' )"][types field='day-of-birth-30' output='raw'][/types][/wpv-conditional]

However, it breaks the process because of the "" - I've tried day='CONDITIONAL CODE GOES HERE'

Any ideas?

Thanks in advance,
Kyle

#2609159

Christopher Amirian
Supporter

Languages: English (English )

Hi Kyle,

First, you need to register the third-party shortcode in Toolset:

https://toolset.com/documentation/legacy-features/views-plugin/shortcodes-within-shortcodes/

Then, to avoid mixup of the content when it comes to usage of " and ', try to create a custom shortcode that incorporated all the conditionals inside that shortcode:

https://toolset.com/documentation/programmer-reference/adding-custom-code/how-to-create-a-custom-shortcode/

Now you will have a clean shortcode that shows the correct data all the time and you can embed it inside an attribute.

If I miss something or did not understand the issue, I'd appreciate it if you can create a separate page with the shortcodes in question and give login information on the next reply with mode details. Make sure you set the next reply as private.

Thanks.

#2609187

My issue is resolved now. Thank you!