0
私はオプションページのACFフィールドを使用して重力フォームドロップダウンにデータを入力しています。値はフィールドから引っ張られていますが、ドロップダウンではなく、フォームの上部に(プレビューで)表示されています。私はこれがフォームの構築方法の問題であると確信しています。事前に助けてくれてありがとう!Gravity Forms動的な人口と高度なカスタムフィールド、選択肢が表示されない
は、私は配列としての選択肢が定義されておらず、ACFのために、機能the_sub_fieldがsub_fieldのエコーのようなものですが、GFフィールドオブジェクトの選択プロパティにそれを伝播し、実際にget_sub_field Screenshot
//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;
}