I’m trying to make a list of users come up in a widget in the admin dashboard. So far i’ve got it showing up, but I want the list to show a custom field from the user’s profile instead of the normal display_name or ID.
My code so far:
function wps_userlist_dw() {
wp_dropdown_users(array('name' => 'author',
'exclude' => '1',
'name' => 'author',
'selected' => $user_id,
'show' => 'ID'
));
}
function add_wps_userlist_dw() {
wp_add_dashboard_widget( 'wps_userlist_dw', __( 'Select a User Below' ), 'wps_userlist_dw' );
}
add_action('wp_dashboard_setup', 'add_wps_userlist_dw' );
So instead of ID, i need a custom field (made via Cimy Extra User Fields – http://wordpress.org/plugins/cimy-user-extra-fields/). Lets say the custom field’s name that i want to show is ‘COMPANYNAME’.
Any thoughts?
If i put in ‘COMPANYNAME’ in the ‘show’ value, the whole function doesn’t show up.
Thanks!!
wp_dropdown_users
accept for show arguments only field from theusers
table, not fromuser_meta
table. If you enable debug, with your code, using ‘companyname’ for$show
argument you will see something like:So, solution is create your customized
wp_dropdown_users
function (wp_dropdown_users_extended
?) just copy the code from the original function and modify it.Tip: What you need is a function that to retierve users (line 1035 of wp function) use a
WP_User_Query
(docs) that run a meta query if$show
is not one of the field in users table, and then use this meta on the output.Probably the function should start like so: