Skip to content

Instantly share code, notes, and snippets.

@khaledsaikat
Last active August 29, 2015 14:06
Show Gist options
  • Save khaledsaikat/7a87e3c39803617325a6 to your computer and use it in GitHub Desktop.
Save khaledsaikat/7a87e3c39803617325a6 to your computer and use it in GitHub Desktop.
Use custom field values as options in a dropdown or checkbox
add_filter( 'user_meta_field_config', 'user_meta_field_config_populate_options', 10, 4 );
function user_meta_field_config_populate_options( $field, $fieldID, $formName, $userID ){
if( $fieldID != 'Your_Field_ID' ) // Put your desired field id here
return $field;
$metaKeys = array( 'key1', 'key2', 'key3' );
$output = null;
foreach( $metaKeys as $key ):
$output .= get_user_meta( $userID, $key, true ) . ',';
endforeach;
$output = ',' . trim( $output, ',' );
$field['options'] = $output;
return $field;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment