title: ACF Dynamically populate a select field’s choices - not completely working
body: <p>So this is an example of my code:</p>
  <pre><code>function acf_populate_age_select( $field ) {
      //Get the values from textarea on option page
      $site_settings = get_field('theme_settings','option');
      $exhibitor_options = $site_settings[0]['exhibitor_options'];
  
      //Turn the values in to an array
      $ages = explode(PHP_EOL,$exhibitor_options['age_groups']);
      
      //Clear the choices
      $field['choices'] = array();
      
      //Repopulate $field['choices']
      foreach ( $ages as $age ) {
          $field['choices'][$age] = $age;
      }
      return $field;
  }
  add_filter( &quot;acf/load_field/key=field_5f451fd1af75e&quot;, 'acf_populate_age_select' );
  </code></pre>
  <p>Taken an example from:</p>
  <p><a href="https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/" rel="nofollow noreferrer">https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/</a></p>
  <p>I am trying to populate a dropdown field's value on load from a textarea field in the options page. It populates fine but I am facing some issues.</p>
  <p>The errors I am encountering are:</p>
  <ul>
  <li><p>if I clear $field['choices'] first, then repopulate it then while the selected value on the page in the database is correct, it resets to the first value in the editor as if the value is saved but the dropdown is rewritten after loading</p>
  </li>
  <li><p>if I don't clear the choices first, old values remain in the dropdown as ghosts even though they can not be found in the database or WP backend</p>
  </li>
  </ul>
  <p>Can anyone see what I am doing wrong or know what I could try to get the dropdown to populate then highlight the currently selected value stored in the database?</p>
  <p>I am using ACF Pro v5.9 on Wordpress v5.5</p>