Last active
September 18, 2018 15:50
-
-
Save yellowstonebum/b0c4f479950baa33678d4ae41e28af2c to your computer and use it in GitHub Desktop.
Gravity Forms - Populate Column with User Meta - Simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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