Support

Account

Home Forums ACF PRO Duplicate values not uploading to select field

Helping

Duplicate values not uploading to select field

  • Hello,

    I am using the select field to create a list of towns and cities associated with their postal codes. So my initial logic was to have the towns as the label, and the post codes as the value. Fairly straight forward.

    However, it appears that the select field does not allow for duplicate values. Where there are several towns with the same postcode, all the towns after the first one are removed from my select list when I update the field. See in the below example, the second 2795 value and its associated label are removed from my select field when I update the field group.

    2850 : Aarons Pass
    2176 : Abbotsbury
    2046 : Abbotsford
    <strong>2795 : Abercrombie</strong>
    <strong>2795 : Abercrombie River</strong>
    2325 : Aberdare
    2359 : Aberdeen
    2336 : Aberdeen
    2350 : Aberfoyle

    Is there a way to allow for duplicate ‘values’ in a select list, or, a way around this problem?

    I actually thought to transpose the town name to be the ‘value’ and use the postcode as the ‘labels’, but then I ran into the problem of my users only seeing the postcodes in the select list when filling out the form (within WordPress dashboard environment).

  • There isn’t a way around this directly. The reason this happens is that ACF stores the values as an array, like this

    
    $field['choices'] = array(
      2850 => 'Aarons Pass'
      2176 => 'Abbotsbury'.
      2046 => 'Abbotsford',
      2795 => 'Abercrombie',
      2795 => 'Abercrombie River',
      2325 => 'Aberdare',
      2359 => 'Aberdeen',
      2336 => 'Aberdeen',
      2350 => 'Aberfoyle',
    )
    

    anywhere you have two array indexes of the same value some of them will be cancelled out.
    I’d suggest using values like ‘2759-1’, ‘2795-2’, or something else that will uniquely identify them and then deal with this in your PHP code.

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

You must be logged in to reply to this topic.