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

  • 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:

    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
                // 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');

    To give further insight into my setup. I have an ACF Options group (Products) setup with repeater fields, looks like this:

    I then have a flexible field setup where the admin can build out products to show on a plan. So various Layouts within a Flexible Content field type. Within each layout is one group where it pulls in the products, like so:

    So each choice relates to the Product added via the ACF Options repeater. These seem to populate nicely initially. Then when adding new products they are not shown as choices in the Post edit screen.

    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?