Home › Forums › Add-ons › Repeater Field › Pre-populate checkbox choices per repeater row › Reply To: Pre-populate checkbox choices per repeater row
Ok thanks for your reply!
I thought I could use the acf_add_local_field
instead for this, so I added the following action that displays my checkboxes correctly now:
add_action('acf/init', array(&$this, 'addServiceMatchMakerFilter'));
public function addServiceMatchMakerFilter() {
if (function_exists('acf_add_local_field')) {
$posts = new Posts();
$global = $posts->getGlobalInfo();
$questions = $global['match_maker_questions'];
// Add field for each match maker question
if (!empty($questions)) {
foreach ($questions as $question) {
$choices = [];
if (!empty($question['choices'])) {
foreach ($question['choices'] as $choice) {
$value = $choice['choice_value'] ? $choice['choice_value'] : $choice['choice_label'];
$choices[$value] = $choice['choice_label'];
}
}
acf_add_local_field([
'key' => 'field_' . uniqid(),
'label' => $question['label'],
'name' => sanitize_title($question['label']),
'type' => 'checkbox',
'parent' => 'field_5d3ebbd2fef0c',
'choices' => $choices,
//'layout' => 'horizontal',
]);
}
}
}
}
However, when saving my post the values from these fields are empty again (also in frontend). Any idea why this is happening?
Thanks, Toine
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.