Last active
August 29, 2015 14:04
-
-
Save UserMetaPro/e0f729103e5b0facac4a to your computer and use it in GitHub Desktop.
Category as options for dropdown/select/multiselect
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_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