Skip Navigation

[Resolved] Using a Conditional To Show Content with Checkboxes

This support ticket is created 7 years 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
- 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)

Tagged: 

This topic contains 7 replies, has 3 voices.

Last updated by Timothy 7 years ago.

Assisted by: Minesh.

Author
Posts
#590949

Hello,

I have a checkbox custom field for the 7 days of the week. In my view I'd like to output other custom fields from that CPT if today's day of week is one of those checkboxes chosen for that post. So for example if the post has Monday, Tuesday, Wednesday checked, and if today is Wednesday the content in the conditional will show.

I've already created a shortcode to output the name of today's day of the week ([day-of-week]). And I've tried:

[wpv-conditional if="( '[types field='happy-hour-days' separator=''][/types]' eq '[day-of-week]' )" ]
Content
[/wpv-conditional]

I also tried [wpv-conditional if="( $(wpcf-happy-hour-days) eq '[day-of-week]' )"]

These did not work, but in the 2nd option if I replaced [day-of-week] with Monday it did work. If I replaced [day-of-week] with any other day it did not. So I'm guessing it's just looking at the first option in this checkboxes field which is Monday and not checking against the other days.

Tim

#590963

y.S

Conditionals don't work with checkboxes.
In many cases changing to select menu can be a workaround.

#591076

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - you can display the conditional output for your checkboxes field as given under:


[wpv-conditional if="( '[types field="movie-industry-roles" option="0"][/types]'  eq '[day-of-week]' )"]
Content
[/wpv-conditional]

[wpv-conditional if="( '[types field="movie-industry-roles" option="1"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]

Important:
- As you are using custom shortcode inside [wpv-conditional] shortcode, you need to register your custom shortcode at:
=> Toolset => Settings => Front-end content tab => Third-party shortcode arguments

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#checkboxes

#591079

Thanks Minesh. And yes I had registered the shortcode [day-of-week] in the Toolset Settings. The shortcode appears to be working fine. The issue appears to be that when the conditional compares wpcf-happy-hour-days to the [day-of-week] it is only checking the first checkbox option which is Monday.

[wpv-conditional if="( $(wpcf-happy-hour-days) eq '[day-of-week]' )"]

As you can see here it works today, which is Monday:

hidden link

But tomorrow there will be no content on the page. Your idea above would work but it will require 7 times the length of code, so 7 times the updating needed when I make changes. I'd really prefer not to use that if possible.

Tim

#591081

Minesh
Supporter

Languages: English (English )

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

Well - I agree that you need to add [wpv-conditional] shortcode 7 times (one conditional statement for one day), but it should need to add one time only.

As you said tomorrow, will be Tuesday, so you would like to display listings belongs to Tuesday - correct? If yes, the code will work as it will display the content for Tuesday only. Did I misunderstand your requirement here?

#591083

Right, so I'd have to write the code like below, so if I ever make a change to the content I'd need to change it in 7 places.

[wpv-conditional if="( '[types field="happy-hour-days" option="0"][/types]'  eq '[day-of-week]' )"]
Content
[/wpv-conditional]
 
[wpv-conditional if="( '[types field="happy-hour-days" option="1"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]

[wpv-conditional if="( '[types field="happy-hour-days" option="2"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]

[wpv-conditional if="( '[types field="happy-hour-days" option="3"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]

[wpv-conditional if="( '[types field="happy-hour-days" option="4"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]

[wpv-conditional if="( '[types field="happy-hour-days" option="5"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]

[wpv-conditional if="( '[types field="happy-hour-days" option="6"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]

[wpv-conditional if="( '[types field="mhappy-hour-days" option="7"][/types]' eq '[day-of-week]' )"]
Content
[/wpv-conditional]
#591085

Minesh
Supporter

Languages: English (English )

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

ahh, you can create a content template and add content template inside the conditional output and later you need to change only one content template.

More info:
=> https://toolset.com/documentation/user-guides/view-templates/

#591086

Ok, that should work. Thanks.

Tim