Support

Account

Home Forums Backend Issues (wp-admin) ACF repeater options used as choices in ACF field Reply To: ACF repeater options used as choices in ACF field

  • Sometimes things get marked as spam for various reasons.

    My understanding is that you have an options page with a repeater on it and you want to populated a select field with the values of that repeater.

    because select field is a sub field in a flex field you should use the field key for your filter.

    
    add_filter('acf/prepare_field/key=FIELD KY OF SELECT', 'populate_FIELD_NAME_from_options');
    function populate_FIELD_NAME_from_options($field) {
      $choices = array();
      if (have_rows('repeater_name', 'options') {
        while (have_rows('repeater_name', 'options') {
          the_row();
          $choices[get_sub_field('value_sub_field')] = $get_sub_field('label_sub_field');
        }
      }
      $field['choices'] = $choices;
      return $field;
    }