0
我使用选项页面中的ACF字段来填充重力形式下拉列表。这些值从字段中拉出,但显示在表单顶部(预览中),而不是下拉列表中。我确信这是我构建表单的一个问题。提前感谢您的帮助!重力形式动态人口和高级自定义字段,选项不显示
//gravity forms dynamically populate from ACF
add_filter('gform_pre_render_1', 'populate_posts');
add_filter('gform_pre_validation_1', 'populate_posts');
add_filter('gform_pre_submission_filter_1', 'populate_posts');
add_filter('gform_admin_pre_render_1', 'populate_posts');
function populate_posts($form) {
global $choices;
foreach ($form['fields'] as &$field) {
if ($field->type != 'select' || strpos($field->cssClass, 'populate-posts') === false) {
continue;
}
if(have_rows('core_values', 'option')):
while(have_rows('core_values', 'option')): the_row();
$choices[] = array('text' => the_sub_field('value_mstr_name'), 'value' => the_sub_field('value_mstr_name'));
endwhile;
// update 'Select a Post' to whatever you'd like the instructive option to be
$field->placeholder = 'Select a Post';
$field->choices = $choices;
endif;
}
return $form;
}