Home › Forums › Backend Issues (wp-admin) › acf/load_field does not dynamically populate other custom fields
I am trying to populate select(multiple) fields with data from repeater fields in option page.
//loadinam ekskursijas i selecta turo single
function acf_load_excursions( $field ) {
$field['choices'] = array();
if( have_rows('excursions', 'options') ) {
while( have_rows('excursions', 'options') ) {
the_row();
$value = get_sub_field('excursions_value');
$label = get_sub_field('excursions_title');
$field['choices'][ $value ] = $label;
}
}
return $field;
}
add_filter('acf/load_field/name=excursions_opt', 'acf_load_excursions');
//loadinam meals i selecta turo single
function acf_load_meals( $field ) {
$field['choices'] = array();
if( have_rows('meals', 'options') ) {
while( have_rows('meals', 'options') ) {
the_row();
$value = get_sub_field('meal_value');
$label = get_sub_field('meal_title');
$field['choices'][ $value ] = $label;
}
}
return $field;
}
add_filter('acf/load_field/name=meals_opt', 'acf_load_meals');
//loadinam transfers i selecta turo single
function acf_load_transfers( $field ) {
$field['choices'] = array();
if( have_rows('transfers', 'options') ) {
while( have_rows('transfers', 'options') ) {
the_row();
$value = get_sub_field('transfer_value');
$label = get_sub_field('transfer_title');
$field['choices'][ $value ] = $label;
}
}
return $field;
}
add_filter('acf/load_field/name=transfers_opt', 'acf_load_transfers');
When I am in post, trying to add/select items in select fields, it doesn’t populate with all repeater entries, first select field only gets last value of repeater, second select fields only get few and last select values seems to be populated correctly.
Ok, I have spotted the problem, it fails to show entries from repeater if it has the same value (repeaters consists of name(string) and value(number), in post im using multiple select field with Ajax. How can I solve this so I could have select options with same values and still see them in admin menu?
Are you still having a problem with this or did the last comment mean that you worked it out?
If you’re still looking for help, are the select fields you’re trying to populate sub fields in a repeater?
You must be logged in to reply to this topic.
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.