Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Last active March 21, 2024 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/190d95ef2090419411398b1563ce83b8 to your computer and use it in GitHub Desktop.
Save codearachnid/190d95ef2090419411398b1563ce83b8 to your computer and use it in GitHub Desktop.
Populate ACF field with list of active Gravity Forms
<?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