Support

Account

Home Forums Add-ons Repeater Field Load repeater choices from same page not options

Solving

Load repeater choices from same page not options

  • I’m trying to dynamically populate a multiple choice field from within the same page as the repeater its pulling from. I could do this with an options section but wanted to keep it all on one page for the admin. This is what I have in my functions.php. I double checked my ID and Key and that the repeater content is saved to the DB.

    /** ACF load Association Filters to API changelog template **/
    function acf_load_Association_Filters( $field ) {
        $field['choices'] = array();
        $post_id = 192115;
        if (have_rows('cl_association', $post_id)) {
            while (have_rows('cl_association', $post_id)) { the_row();
                $value = get_sub_field('ca_filter_name');
                $label = get_sub_field('ca_filter_id');
                $field['choices'][ $value ] = $label;
            }
        }
        return $field;
    }
    add_filter('acf/load_field/key=field_64b6e38fc27db', 'acf_load_Association_Filters');
  • I don’t see any reason why this wouldn’t work except that it will not update the select field as more values are added to the repeater. The post would need to be saved for the new choices to be added.

    Also, if you want to use the current post then you would need to provide the post ID of the current post rather than a hard coded ID.

  • Thanks for the response. The hard coded post ID is the one I’m trying to get to work. It’s only the one custom post type post for now. I’ve since decided to do it with a regular ACF Options section and thats working well enough. Still seemed like it should have worked though.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.