How can I display only the Other choice in a Checkbox field?

By: George Plumley | Asked: 10/26/2023
ForumsCategory: How-toHow can I display only the Other choice in a Checkbox field?
George Plumley asked 1 year ago

I'm building a table that shows the options people chose for a Checkbox field, like this:

[if 898 like="Capacity"]<span class="checkmark">Yes</span>[/if 898]

[if 898 like="Finances"]<span class="checkmark">Yes</span>[/if 898] etc.

but the field includes an Other option, and I'm trying to figure out how to display ONLY the value for Other.

I'm thinking I'll need to write a custom shortcode for this, but just wondered if I'm missing some other answer.

Thanks!

3 Answers
George Plumley answered 1 year ago
When I look at the HTML of the form containing one of these Checkbox fields, I can see that the name of the Other field is: item_meta[other][942][other_10] It's looking like I need a custom shortcode to extract this data or does anyone know of an existing shortcode that does this. I haven't found one in the documentation.  
Rob LeVineRob LeVine answered 1 year ago
I've read this multiple times and honestly, I'm still not sure what you're trying to do. That being said, I'll answer based on my own assumptions. Assuming "building a table" means you're in a view, I suggest a custom shortcode that uses a switch statement for the hardcoded values in the list and the default case for the "other". I'm not sure if you realize that the value in [898] in the Other case is whatever value the user entered, so that all you really know is that it's not Capacity, not Finances etc. The provided example is odd in that in both the Capacity and Finances case, you're outputting the same value, though I guess you meant to put a label in there as well.
George Plumley answered 1 year ago
Hi Rob! I've only ever spit out Other values as part of spitting out all the checkbox values. In this instance, we're separating each checkbox value into a column, so I needed to isolate the Other value. I was thinking that when the checkbox values are stored, that there was some sort of flag to say "this is the Other value", but when I checked in the database, it does not. So, as you say, what I have to do in my custom code, is loop through all the checkbox values, and the one that doesn't match any of the hard-coded values must be the Other value. Thanks!

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