Home › Forums › ACF PRO › How to Select Repeater Data from a Dropdown › Reply To: How to Select Repeater Data from a Dropdown
Now that I look at what I have. I have a class that sores the repeater in an array so I don’t need to get it every time. Here is a very simple example:
<?php
new your_class_name();
class your_class_name {
private $cta_choices = array();
public function __construct() {
add_filter('acf/prepare_field/name=your_field_name', array($this, 'choices'));
}
public function choices($field) {
if (!empty($this->cta_choices)) {
$field['choices'] = $this->cta_choices;
return $field;
}
if (have_rows('cta_repeater', 'options')) {
$choices = array();
while (have_rows('cta_repeater', 'options')) {
the_row();
$class = get_sub_field('id_field_name'); // this is my unique ID field
$text = get_sub_field('title_field_name');
$choices[$class] = $text;
} // end while have rows
$field['choices'] = $choices;
}
$this->cta_choices = $field['choices'];
return $field;
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.