Home › Forums › General Issues › ACF Dynamically populate a select field’s choices, even when values are the same › Reply To: ACF Dynamically populate a select field’s choices, even when values are the same
Interesting. My labels will always be unique though, so I could switch them over.
NOPE – Just realised if I do that, the user on the backend is picking from a random list of numbers, it is the complete list though 🙂
So instead I think the solution is to populate that select box with JUST the label..
if ( have_rows( 'protein', 2564 ) ) {
// while has rows
while( have_rows('protein', 2564) ) {
// instantiate row
the_row();
$type = get_sub_field('class', 2564);
$value = get_sub_field('grams', 2564);
$label = get_sub_field('food_name', 2564);
// append to choices
$field['choices'][ $label ] = $label;
}
}
(theres definitely a more streamline way of doing that)
…and then to use that label to find the matching ‘grams’ number back on the options page (ID=2564). The problem is ‘grams’ is not a subfield of the food name, but rather a sibling.
I’m sure there’s a solution here, just need to give it some thought.
Thanks for your help, sorry for the rambling 🙂
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.