Skip Navigation

[Resolved] Output only one checkbox from a checkboxes field

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 7 years ago.

Assisted by: Beda.

Author
Posts
#582758

Hi,

I have a checkboxes field with about 25 checkboxes for the user to select. I'd like to be able to do 2 things:

1) Output just first checkbox that the user has selected

2) Output one random checkbox that the user has selected

I thought this might work for 1) but it doesn't:
[types field='ambiance' index='0'][/types]

Thank you for your assistance.

Tim

#582920

This will only work if you edit the ShortCode manually or write some Custom Code to do that.

With Toolset you can display Checkboxes in different ways, no matter if in a Single Post or in a Views Loop.
You need at least Types and Views for this.

1. Display the value of this field from the database
This will display what is saved for the field. Note that fields can either save nothing or 0 when they are not checked.
Usually checked values will be "1" unless set differently in Toolset > Post Fields.

[types field='toolset-cehckboxes' option='0'][/types]
[types field='toolset-cehckboxes' option='1'][/types]
[types field='toolset-cehckboxes' option='2'][/types]

With this you can already control what part of the field to display (you could as example omit the first option)

2. Display all values with a separator
This is basically the same as #1, you just control the separator.

3. Enter values for 'selected' and 'not selected' states
You will enter values to display for each checkbox of the checkboxes and for each case (checked or not).

[types field='toolset-cehckboxes' option='0' state='checked']sel[/types]
[types field='toolset-cehckboxes' option='0' state='unchecked']not sel[/types]

[types field='toolset-cehckboxes' option='1' state='checked']empty[/types]
[types field='toolset-cehckboxes' option='1' state='unchecked']etc[/types]

[types field='toolset-cehckboxes' option='2' state='checked'][/types]
[types field='toolset-cehckboxes' option='2' state='unchecked'][/types]

These are the only methods to address the items in a checkboxes field.
Or, if you write custom code.

Checkboxes are complex arrays of arrays (of arrays).
Hence, I suggest to look at some examples how you can access those values with Custom Code:
https://pastebin.com/wz6dQVBE > line 21 onwards deals with checkboxes.

Unfortunately it is not possible to loop through the Checkboxes like through a posts list.