Skip to content

Instantly share code, notes, and snippets.

@yellowstonebum
Last active September 18, 2018 15:50
Show Gist options
  • Save yellowstonebum/b0c4f479950baa33678d4ae41e28af2c to your computer and use it in GitHub Desktop.
Save yellowstonebum/b0c4f479950baa33678d4ae41e28af2c to your computer and use it in GitHub Desktop.
Gravity Forms - Populate Column with User Meta - Simple
<?php
// The following snippet will populate a List Field's dropdown with another forms entries.
// Direct the snippet to populate the field with "gform_column_input_42_1_3". 42 being the
// field, 1 being the field, and 3 being the column
// BE AWARE - changing the column in the list field will break this snippet
add_filter( 'gform_column_input_42_1_3', 'business_column', 10, 5 );
function business_column( $input_info, $field, $column, $value, $form_id ) {
$items = array();
// Input the type of meta you want to look got and the defining result. For me this was users with the role of "company".
$metas = get_users( array( 'role' => 'company' ) );
if (is_array($metas))
{
// Now using the User Meta we've obtained we can choose the Value and Text of the dropdown.
// I wanted the Display Name but you can display any collected meta data
foreach($metas as $meta) $items[] = array("value" => $meta->display_name, "text" => $meta->display_name);
}
return array( 'type' => 'select', 'choices' => $items );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment