Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Add User ID Column to the WordPress Users Table

Posted on November 2, 2011 by Pippin in Intermediate, Quick Tips, Tutorials, WordPress Admin / Dashboard 16 Comments
Home» Tutorials » Intermediate » Add User ID Column to the WordPress Users Table
Tweet
Love It - 0

Being able to quickly find the unique ID number of any user in your WordPress database can be very useful, especially if you run a website with lots of users. One of the ways that we can easily find a user’s ID is by customizing the table displayed on the wp-admin/users.php page. We can add a custom column that will display the ID number of every user.


This is a quick tip. Check out more Quick Tips

To add the user ID column, you can either copy this code into your functions.php, or add it as its own plugin.

1
2
3
4
5
6
7
8
9
10
11
12
13
add_filter('manage_users_columns', 'pippin_add_user_id_column');
function pippin_add_user_id_column($columns) {
    $columns['user_id'] = 'User ID';
    return $columns;
}
 
add_action('manage_users_custom_column',  'pippin_show_user_id_column_content', 10, 3);
function pippin_show_user_id_column_content($value, $column_name, $user_id) {
    $user = get_userdata( $user_id );
	if ( 'user_id' == $column_name )
		return $user_id;
    return $value;
}

Using the same methods as I have here, you could very easily add custom columns for even more user attributes, such as the user’s comment count.

Tweet Follow @pippinsplugins
columns, users, user_id

16 comments on “Add User ID Column to the WordPress Users Table”

  1. Spencer Hill says:
    May 9, 2012 at 5:20 pm

    Thanks for sharing this solution, is there a way to change the order of the column so the user ID can appear as the first column?

    Reply
    • Pippin says:
      May 10, 2012 at 8:10 pm

      Yes, all you need to do is make the ['user_id'] column be the first item in the array. Do you know how to do that?

  2. Steve says:
    May 29, 2012 at 8:36 am

    Hi,

    Is there a way to show this column second (after the checkbox and ‘username’ column)?

    Also is it possible to make it sortable?

    Reply
    • Pippin says:
      May 29, 2012 at 8:50 pm

      Yes, you can make it the second column. All of the columns shown on the user page are available in the $columns array, so all you have to do is set the “user_id” column to the second index. Does that make sense?

      For making it sortable, I’d suggest you read through this thread.

  3. Steve says:
    May 29, 2012 at 9:31 pm

    Hi Pippin,

    Thanks for your help. I think I have to split the array is this correct? I have no idea how to do that.

    I also wasn’t able to get the sorting working from that article.


    add_filter('manage_users_columns', 'pippin_add_user_id_column');
    function pippin_add_user_id_column($columns) {
    $columns['displayname'] = 'Display Name';
    return $columns;
    }
    add_filter( 'manage_users_sortable_columns', 'pippin_add_user_id_column' );

    function user_column_orderby( $vars ) {
    if ( isset( $vars['orderby'] ) && 'displayname' == $vars['orderby'] ) {
    $vars = array_merge( $vars, array(
    'meta_key' => 'displayname',
    'orderby' => 'meta_value',
    'order' => 'asc'
    ) );
    }
    return $vars;
    }
    add_filter( 'request', 'user_column_orderby' );

    function add_user_columns( $defaults ) {
    $defaults['displayname'] = __('Display Name', 'user-column');
    return $defaults;
    }

    function pippin_show_user_id_column_content($value, $column_name, $user_id) {
    $user = get_userdata( $user_id );
    if ( 'displayname' == $column_name )
    return $user->display_name;
    }
    add_action('manage_users_custom_column', 'pippin_show_user_id_column_content', 10, 3);
    add_filter('manage_users_columns', 'add_user_columns');

    Reply
    • Pippin says:
      May 30, 2012 at 9:48 am

      Probably the easiest way would be to sort the $columns array. See here for some examples: http://php.net/manual/en/array.sorting.php

  4. Zeal says:
    June 7, 2012 at 4:56 am

    How do i upate one particular user colum field on the database?

    Reply
    • Pippin says:
      June 7, 2012 at 3:07 pm

      That’s not relevant to this tutorial, but you will need to look at the update_user_meta() function.

  5. ronnie says:
    August 23, 2012 at 12:28 pm

    hi pippin,
    Your solution is exclacty what I need!
    But I dont understand how to implement it..!
    tks! Ronnie

    Reply
    • Pippin says:
      August 23, 2012 at 8:17 pm

      Placing this code in your functions.php of your active theme should do it for you.

  6. Kailey Lampert says:
    January 16, 2013 at 3:11 pm

    Be sure to always return $value in the manage_users_custom_column callback so you don’t accidentally overwrite other plugins’ columns.

    Reply
    • Pippin says:
      January 23, 2013 at 9:53 pm

      Whoops! Fixed :)

  7. paulmarr says:
    February 1, 2013 at 5:44 am

    Thanks pipin , thanks for the code. can you do one help . i need to make it ascending/descending like the columns username,email etc . please reply me.

    Reply
    • Pippin says:
      February 4, 2013 at 11:47 am

      That goes far beyond the scope of this tutorial, sorry.

  8. James says:
    March 21, 2013 at 6:17 pm

    How would you modify this code to return the ‘user_description’ field from get_user_meta? I’ve tried, but I keep getting the ID# or error messages:

    add_filter('manage_users_columns', 'custom_add_user_id_column');
    function custom_add_user_id_column($columns) {
    $columns['user_description'] = 'Company / Role';
    return $columns;
    }

    add_action('manage_users_custom_column', 'custom_show_user_id_column_content', 10, 3);
    function custom_show_user_id_column_content($value, $column_name, $user_id) {
    $user = get_userdata( $user_id );
    if ( 'user_description' == $column_name )
    return $user_id;
    return $value;
    }

    Reply
    • Pippin says:
      March 22, 2013 at 4:27 pm

      Change “user_description” to “description”.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

  • User Follow System – Part 1
  • User Bookmarks for WordPress
  • User Submitted Image Gallery – Part 3
  • User Submitted Gallery Images – Part 2
  • User Submitting Gallery Images – Part 1

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes

Latest Tutorials

  • Storing Session Data in WordPress without $_SESSION (19)

    The term Session in web development refers to...

  • Test Your Plugins with RTL (1)

    Right-To-Left languages are those that...

  • Submitting Your First Pull Request to a WordPress Plugin on Github (5)

    Github is an extremely popular tool for managing WordPress plugins, and one...

Enter your email to receive automated updates when new posts are published

WP Core Contributions

  • [24316]

View the ticket on Trac.

WP Codex Contributions

  • Function: shortcode exists
  • Function: has shortcode
  • Function: shortcode exists
  • Function: shortcode exists
  • Function: has shortcode

View all 41 changes in the Codex.

Latest Tweets

  • Could not fetch Twitter RSS feed.

Topics

campaign monitor add_options_page hook get_user_meta Rémi Corson the_content meta box register_setting Sugar Event Calendar attachments wp_enqueue_script contextual help shortcodes authors Related posts attachment image forms do_action plugin mail chimp login short codes comments recent posts post types apply_filters short code bbpress taxonomies custom post type gallery images Ajax Stripe taxonomy jquery widgets users add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2013 Pippin's Plugins