title: ACF: Dynamically populate select field with repeater relationship subfield
body: <p>Used the awesome solution <a href="https://stackoverflow.com/questions/35502576/how-to-get-advanced-custom-field-choice-value-from-another-advance-custom-field/35503328">here</a> to populate multiple select fields with text fields inside a repeater field. The issue is I need to use a user (relational) field instead and this field is returning anything in the select box. This is the code I'm using, wondering if I need to call a relational field in a different way..?</p>
  
  <p>FYI:</p>
  
  <ul>
  <li>Repeater field is <code>co_designated_employee_representative</code></li>
  <li>User field is <code>co_der</code></li>
  <li>Select field to be populated is <code>test_selection</code></li>
  </ul>
  
  <p>Here is my snippet:</p>
  
  <pre><code>function acf_load_marke_name_field_choices($field)
   {
  global $post;
  //Get the repeater field values
  $choices = get_field('co_designated_employee_representative',$post-&gt;ID);
  // loop through array and add to field 'choices'
  if (is_array($choices)) {
      foreach ($choices as $choice) {
          //Set the select values
          $field['choices'][$choice['co_der']] = $choice['co_der'];
      }
  }
  
  // return the field
  return $field;
  } 
  
  add_filter('acf/load_field/name=test_selection', 'acf_load_marke_name_field_choices');
  </code></pre>
  
  <p>EDIT**</p>
  
  <p>Found that if I added the select field name to the first $choice I ended up with an array of usermeta.</p>
  
  <pre><code>function select_my_field($field)
   {
  global $post;
  //Get the repeater field values
  $choices = get_field('co_designated_employee_representative',$post-&gt;ID);
  // loop through array and add to field 'choices'
  if (is_array($choices)) {
  foreach ($choices as $choice) {
      //Set the select values
      $field['choices'][$choice['test_selection']] = $choice['co_der'];
      }
  }
  
  // return the field
  return $field;
  } 
  
  add_filter('acf/load_field/name=test_selection', 'select_my_field'); 
  </code></pre>
  
  <p>This change gave me all the chosen usermeta in the select dropdown, but I (a) only need first and last name and (b) if more than one user was chosen the select field would only show usermeta for the last user in the repeater field.</p>
  
  <p><a href="https://i.stack.imgur.com/zXz5B.jpg" rel="nofollow noreferrer">Screenshot of populated select field</a></p>