Skip to content

Instantly share code, notes, and snippets.

@ravinderk
Created September 15, 2015 07:59
Show Gist options
  • Save ravinderk/f1d01fd4e65d52ab755b to your computer and use it in GitHub Desktop.
Save ravinderk/f1d01fd4e65d52ab755b to your computer and use it in GitHub Desktop.
/**
* Add gravity forms to acf gravityform select field
*
* @param array $field field data.
*
* @return mixed
*/
function acf_load_color_field_choices( $field ) {
// Reset choices.
$field['choices'] = array();
// Add gravity form to choices.
if ( class_exists( 'RGFormsModel' ) ) {
$forms = RGFormsModel::get_forms( null, 'title' );
foreach ( $forms as $index => $form ) {
if( ! $index ){
$field['choices'][ 'none' ] = 'None';
}
$field['choices'][ $form->id ] = $form->title;
}
}
// Return the field.
return $field;
}
add_filter( 'acf/load_field/name=gravity_form', 'acf_load_color_field_choices' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment