如何动态填充转发器字段内的复选框值

How to dynamically populate checkbox value inside repeater field

我可以使用此代码在一个简单的自定义字段中使用我的自定义 post "features" 填充复选框值,其中我的字段名称是 "simple_field".

function acf_load_features_field_choices( $field ) {

    $field['choices'] = array();

    $features = get_posts(array(
        'post_status'  => 'publish',
        'post_type' => 'features',
        'posts_per_page' => -1,
        'orderby' => 'title',
        'order' => 'ASC'
    ));

    foreach( $features as $feature ) {
        $value = $feature->ID;
        $label = $feature->post_title;

        $field['choices'][ $value ] = $label;
    }

    return $field;
}

add_filter('acf/load_field/name=simple_field', 'acf_load_features_field_choices');

但我需要填充一个位于转发器字段内的复选框字段,其中我的转发器字段名称为 "feature_item",复选框字段名称为 "list".

正如埃利奥特所说 form. Try to use the key of the subfield. Here you can find how to view the key of the field

add_filter('acf/load_field/key={your key here}', 'acf_load_features_field_choices');