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' );
@SjorsHartwijk
Copy link

SjorsHartwijk commented Apr 28, 2021

Great solution! How do i display the selected form on my page? The value from the select box is the form ID.

@psaikali
Copy link
Author

psaikali commented Apr 28, 2021

Hey @SjorsHartwijk

You're looking for the gravity_form() function, see https://docs.gravityforms.com/adding-a-form-to-the-theme-file/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment