Last active
April 28, 2023 08:34
-
-
Save mattiasghodsian/b08a737bac1eb9fdbb4ddac886e52187 to your computer and use it in GitHub Desktop.
[WordPress] Populate ACF select field options with Gravity Forms forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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