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;
}