Skip to content

Instantly share code, notes, and snippets.

@psaikali
Created January 4, 2019 13:43
Show Gist options
  • Save psaikali/2b29e6e83f50718625af27c2958c828f to your computer and use it in GitHub Desktop.
Save psaikali/2b29e6e83f50718625af27c2958c828f to your computer and use it in GitHub Desktop.
Populate ACF select field options with Gravity Forms to select a specific form
<?php
/**
* Populate ACF select field options with Gravity Forms forms
*/
function acf_populate_gf_forms_ids( $field ) {
if ( class_exists( 'GFFormsModel' ) ) {
$choices = [];
foreach ( \GFFormsModel::get_forms() as $form ) {
$choices[ $form->id ] = $form->title;
}
$field['choices'] = $choices;
}
return $field;
}
add_filter( 'acf/load_field/name=submit_project_gf_form_id', 'acf_populate_gf_forms_ids' );
@davidhyland
Copy link

This is fantastic! Exactly what I was looking for and just worked, thank you. Adding the 'none' option is good idea too. Kudos for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment