Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/functions.php Secret
Created Feb 25, 2019

Embed
What would you like to do?
<?php
/**
* Dynamically select form in ACF
* @see https://www.billerickson.net/dynamic-dropdown-fields-in-acf/
* @author Bill Erickson
*
* @param array $field, the field settings array
* @return array $field
*/
function be_acf_select_form( $field ) {
// These are the field names we're updating
$form_fields = array(
'ea_subscribe_form',
'ea_registration_form,'
);
if( ! in_array( $field['name'], $form_fields ) )
return $field;
// Get form list from Gravity Forms
if( ! class_exists( 'GFAPI' ) )
return $field;
$forms = GFAPI::get_forms();
// Build list of choices
$field['choices'] = array( 0 => '(None)' );
foreach( $forms as $form ) {
$field['choices'][ $form['ID'] ] = $form['title'];
}
return $field;
}
add_filter( 'acf/load_field', 'be_acf_select_form' );
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.