Last active
March 21, 2024 18:12
-
-
Save codearachnid/190d95ef2090419411398b1563ce83b8 to your computer and use it in GitHub Desktop.
Populate ACF field with list of active Gravity 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
<?php | |
/*** | |
* Populate ACF field (list_gravity_forms) with list of active Gravity Forms | |
***/ | |
add_filter( 'acf/load_field/name=list_gravity_forms', function( $field ) { | |
$forms = GFFormsModel::get_forms(); | |
// Filter active forms | |
$forms = array_filter( $forms, function( $form ) { | |
return !rgar( $form, 'is_trash' ); | |
}); | |
if ( is_array( $forms ) ) { | |
$field[ 'choices' ] = []; | |
$field[ 'choices' ][] = 'Select form'; | |
foreach($forms as $form) { | |
$field[ 'choices' ][ $form->id ] = $form->title; | |
} | |
} | |
return $field; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment