Home › Forums › Backend Issues (wp-admin) › ACF repeater options used as choices in ACF field › Reply To: ACF repeater options used as choices in ACF field
https://g.page/madeybfuse/review?rc
Hi John, I initially used the ‘Dynamically populate a select field’s choices’ you mentioned above, I have updated the code I had, changing all instances of ‘load_field’ to ‘prepare_field’.
Unfortunately, that didn’t work.
Here is my code:
// the following pulls in content from an options page into a select field, see here:
// https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/
function acf_prepare_product_field_choices( $field ) {
// reset choices
$sub_field['products'] = array();
// if has rows
if( have_rows('product', 'option') ) {
// while has rows
while( have_rows('product', 'option') ) {
// instantiate row
the_row();
// vars
$value = get_sub_field('application_rate');
$label = get_sub_field('title');
$ar = get_sub_field('application_rate');
// append to choices
$sub_field['products'][ $value ] = $label;
}
}
// return the field
return $field;
}
add_filter('acf/prepare_field/name=products', 'acf_prepare_product_field_choices');
I thought that changing ‘load_field’ to ‘prepare_field’ might do it, no such joy. I’m guessing I’ve done something wrong along the way?
Thanks
Lee
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 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.