Skip to content

Instantly share code, notes, and snippets.

@UserMetaPro
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UserMetaPro/e0f729103e5b0facac4a to your computer and use it in GitHub Desktop.
Save UserMetaPro/e0f729103e5b0facac4a to your computer and use it in GitHub Desktop.
Category as options for dropdown/select/multiselect
add_filter( 'user_meta_field_config', 'user_meta_field_config_populate_categories', 10, 3 );
function user_meta_field_config_populate_categories( $field, $fieldID, $formName ){
if( $fieldID != 'Your_Field_ID' ) // Put your desired field id here
return $field;
$output = null;
$cats = get_categories();
foreach( $cats as $cat ):
$output .= $cat->term_id.'='.$cat->name.',';
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