Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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' );
@zartgesotten

This comment has been minimized.

Copy link

commented Apr 25, 2019

Thank you very much! It does exactly what I need but I have one remaining question: How would I be able to have a first (default) selection that is empty, so I can have no form when none is selected? Basically I need the FIRST select option to be "None", defaulted to the value 0 ...
THANKS so much!

@gargiguy

This comment has been minimized.

Copy link

commented May 22, 2019

Thank you very much! It does exactly what I need but I have one remaining question: How would I be able to have a first (default) selection that is empty, so I can have no form when none is selected? Basically I need the FIRST select option to be "None", defaulted to the value 0 ...
THANKS so much!
@zartgesotten
You can add something like:
$choices[ $form->id ] = 'Select a form';
Before the "foreach" loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.