Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:34
Show Gist options
  • Save mattiasghodsian/b08a737bac1eb9fdbb4ddac886e52187 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/b08a737bac1eb9fdbb4ddac886e52187 to your computer and use it in GitHub Desktop.
[WordPress] Populate ACF select field options with Gravity Forms forms
/**
* Title: Populate ACF select field options with Gravity Forms forms
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
function acf_populate_gf_forms_ids( $field ) {
if ( class_exists( 'GFFormsModel' ) ) {
$choices = [];
// $choices[ $form->id ] = 'Select a form';
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment