Looping through checkbox values in a view

By: Patrick Nethery | Asked: 06/16/2022
ForumsCategory: Code HelpLooping through checkbox values in a view
Patrick Nethery asked 3 years ago
I am pulling a list of values (topics) from form 1 to form 2 via a lookup field and presenting the values in form 2 as checkboxes and then displaying the values (as hyperlinks) in a view. However, I cannot find a way to loop through the (checkbox) values in a way that will allow me to construct a custom URL specific to each value.  The closest thing I can find is [x sep=", " ] but (as far as I know) that will not allow variable use within. Is there some way to do this similar to the [foreach] that can be used for repeaters?   Simple Overview of my Forms / Views Form 1 = Topics Form 2 = Courses with Topic field pulled from Form 1 values as checkboxes in Form 2. Form 2 View = Loop through Topic values checked in Form 2 and construct a custom hyperlink for each that links back to the topic view to show courses for that topic.   Please let me know if this is possible or if there is another way to achieve the same thing. Thanks!! - Patrick
1 Answers
Victor Font answered 3 years ago
There is no way to natively loop through a multi-select checkbox in a view. I would create a custom shortcode to display the values as hyperlinks. The thing to be aware of is multi-checkbox values are stored in the database as serialized arrays. They need to be unserialized before you can loop through the array. If a checkbox only has one selection, it is stored in the database as plain text, not a serialized array.
Patrick Nethery replied 3 years ago

Thanks Victor!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right