I know that is an old topic but it worked for me also and I have a question.
How can we save the selected value from this select field?
I tried with the following code but it returns null update_field($field, $field['value']
Finally, I’ve managed to succesfully populate the repeater field in a select field in every users panel with this function
function acf_load_select_field_field_choices($field) {
global $current_user;
//Get the repeater field values
$choices = get_field('repeater_field_name',$current_user);
$field['choices'] = [];
// loop through array and add to field 'choices'
if (is_array($choices)) {
foreach ($choices as $choice) {
//Set the select values
$field['choices'][$choice['subfield']] = $choice['subfield'];
}
}
// return the field
return $field;
}
add_filter('acf/load_field/name=select_field', 'acf_load_select_field_field_choices');
The only problem that I’m facing right now is that the select field doesn’t update when submitting a form.
The code that I’m using to display and update the select field is the following
<?php
$field = get_field_object('repeater_field_key');
if (!empty($field['choices'])) { ?>
<select>
<?php foreach ($field['choices'] as $v => $l) { ?>
<option value="<?php echo $v; ?>"><?php echo $l; ?></option>
<?php } ?>
</select>
<?php }
$current_user_id = get_current_user_id();
update_field($field, $field['value'], 'user_'.$current_user_id);
?>
What am I doing wrong?
Actually you helped a lot.
I was trying to populate the choises from a field group that was showing on users.
Is it possible to do this on a field group that is showing somewhere else besides options page?
I’m trying to show this field group on users panel but the populate functions doesn’t work there.
UPDATE
So I’ve managed to display the repeater field as a select box with the following code
<select name="cars" id="cars">
<?php
// Check rows existexists.
// Loop through rows.
while( have_rows('yacht_type1') ) : the_row();
// Load sub field value.
$sub_value = get_sub_field('name');
// Do something...
echo '<option value="'.$sub_value.'">'.$sub_value.'</option>';
endwhile;
?>
</select>
Now what I’m actually searching for is how to get and store the value from the select box.
After doing some research I think that the best way to achieve this is by creating a repeater field with a text subfield.
The question now is how can I display this repeater field as a select field with the values of the text subfields and how can I save the value from the select field choise (the repeater field will display in a registration form).
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.