Home Forums General Issues Can you have named keys for check box fields?


Can you have named keys for check box fields?

  • Hi there.
    When creating a number of check box fields…ACF creates a numerically indexed array with the field Labels/Values as the value to numbered indexes. Is there a way to have the label be the key and 1/0 be the value?

    I have check boxes to select the color(s) of something…and it would be much easier to deal with the data if it was:


    instead of:

    Hope that makes sense. Can it be done?

  • No, but you can specify both the key (value) and the label

    red : 1
    green : 0
    blue : 1

    Not sure if that helps, but I don’t quite understand what you’re trying to do.

  • Yeah, I tried messing with that but it appears to be label:value not key:value. They key still remains numeric.

    I’m trying to find similarities and differences between two arrays that are populated with ACF data. The issue becomes that the positions of values change between different arrays based on whether the values exist…so comparison becomes complicated. Not insurmountable…just more complicated.

  • It depends on the return value setting what you get back. get field will always be numeric keys. If you want both label and value or just the label there is a setting for that. If you need something more complicated then you need to get what’s available and create it yourself using PHP functions.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.