Create dropdown of users in admin dashboard

wp_dropdown_users accept for show arguments only field from the users table, not from user_meta table. If you enable debug, with your code, using ‘companyname’ for $show argument you will see something like:

WordPress database error: [Unknown column ‘wp_users.companyname’ in
‘field list’]
SELECT
wp_users.ID,wp_users.user_login,wp_users.companyname FROM wp_users
WHERE 1=1 ORDER BY display_name ASC

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:

function wp_dropdown_users_extended( $args = array() ) {
  $std_fields = array('ID', 'user_login', 'user_nicename', 'user_email', 'user_url', 'display_name');
  if ( isset($args['show']) && in_array($args['show'], $std_fields) ) {
    if ( isset($args['echo'] && ! $args['echo'] )
      return wp_dropdown_users($args);
    else
      wp_dropdown_users($args);
  } else {

    // copy here the code from wp_dropdown_users and customize it ;)    

  }
}