Support

Account

Home Forums ACF PRO How to Stop ACF Stripping Duplicates in Choices Field?

Solving

How to Stop ACF Stripping Duplicates in Choices Field?

  • I THINK ACF is stripping duplicate options from a choices field I have.

    I need to keep the duplicates because I have some custom code to turn some options into OPTGROUPS in a dropdown, and we want the same options to appear in several OPTGROUPS. But they wont save, all duplicated ones are stripped out on saving.

    Is there a way to prevent this? I dont think its good to change the data I want to save.

    Thanks

  • No, there isn’t a way to stop this. The way that ACF works does not have the ability to have options groups and it does not allow multiple duplicate values. Why? ACF stores the choices your enter in an array that looks something like this:

    
    $field = array(
      // other field settings
      'choices' => array(
        'value 1' => 'label 1',
        'value 2' => 'label 2',
        // etc...
      ),
      // other field settings
    )
    

    The problem here is that PHP does not allow duplicate array index values, which is where your choice value lives.

  • Yes that makes sense, but such a shame it works this way. I wonder if I can add the duplicates as value1, value2 etc. and then enter the Label the same, so Value as the label for each one.

  • as long as the values are different is some way they will be fine. value1, values1A, value1B… Your only other real choice would be to create a new field type that worked in some other way.

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

The topic ‘How to Stop ACF Stripping Duplicates in Choices Field?’ is closed to new replies.