如何在中继器字段中动态填充复选框值

时间:2018-12-03 07:54:53

标签: wordpress advanced-custom-fields acfpro

我可以使用此代码在一个简单的自定义字段中用我的自定义帖子“功能”填充复选框的值,其中我的字段名称为“ 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”。

1 个答案:

答案 0 :(得分:1)

正如Elliot在此form上所说。尝试使用子字段的键。 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');