Last active
August 29, 2015 14:06
-
-
Save khaledsaikat/7a87e3c39803617325a6 to your computer and use it in GitHub Desktop.
Use custom field values as options in a dropdown or checkbox
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
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