The code should be added in a separate file and then included in your functions.php
using require
.
Replace 1 from the code with the ID of the form that you want to dinamically populate with field values from ACF. You can find more info about the filters in the Gravity Forms documentation.
add_filter( 'gform_pre_render_1', 'populate_dropdown' );
add_filter( 'gform_pre_validation_1', 'populate_dropdown' );
add_filter( 'gform_admin_pre_render_1', 'populate_dropdown' );
add_filter( 'gform_pre_submission_filter_1', 'populate_dropdown' );
if ( $form['id'] != 1 ) {
return $form;
}
if ( $field->id == 1 ) {
$field->choices = $dropdownitems;
}
Hello @zmayyem! I'm glad someone else found this bit of code useful.
To make it work with a Taxonomy Object field you need to tweak the foreach loop between lines 25 and 30. It should look like this:
Haven't tested the code but this should do it.
Good luck!