How to add a Sortable User Registration Date Column to the All Users page
Example: let’s suppose that there was a spam attack on your website and there were registered near 50 spam users. But your website has 1000 users. How to remove the recent 50 users without going directly to database?
And here is the solution.
The following code is ready to use, you can insert it even without changes to your current WP theme functions.php
file.
/*
* Create a column. And maybe remove some of the default ones
* @param array $columns Array of all user table columns {column ID} => {column Name}
*/
add_filter( 'manage_users_columns', 'rudr_modify_user_table' );
function rudr_modify_user_table( $columns ) {
// unset( $columns['posts'] ); // maybe you would like to remove default columns
$columns['registration_date'] = 'Registration date'; // add new
return $columns;
}
/*
* Fill our new column with the registration dates of the users
* @param string $row_output text/HTML output of a table cell
* @param string $column_id_attr column ID
* @param int $user user ID (in fact - table row ID)
*/
add_filter( 'manage_users_custom_column', 'rudr_modify_user_table_row', 10, 3 );
function rudr_modify_user_table_row( $row_output, $column_id_attr, $user ) {
$date_format = 'j M, Y H:i';
switch ( $column_id_attr ) {
case 'registration_date' :
return date( $date_format, strtotime( get_the_author_meta( 'registered', $user ) ) );
break;
default:
}
return $row_output;
}
/*
* Make our "Registration date" column sortable
* @param array $columns Array of all user sortable columns {column ID} => {orderby GET-param}
*/
add_filter( 'manage_users_sortable_columns', 'rudr_make_registered_column_sortable' );
function rudr_make_registered_column_sortable( $columns ) {
return wp_parse_args( array( 'registration_date' => 'registered' ), $columns );
}
- Line 9
- This piece of code helps you to remove any of the default columns, these columns are:
name
,email
,role
,posts
but remember that you can just hide some of these columns in «Screen Options». - Line 26
- Date format to display. You can use any format that supported by
date()
PHP function. - Line 30
- Here
get_the_author_meta()
function returns the date user registered in the same format it is stored in database:2017-02-09 05:37:39
- Line 46
- We need
wp_parse_args()
to merge two arrays. If$columns
array already contains the element withregistration_date
key, this element value will be updated.
If the column haven’t appeared in your WordPress admin area on the Users > All Users page or maybe you would like to hide the other columns without code — try to use «Screen Options» tab then.
If you have any questions left I’m ready to help you in comments.

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
It is a very handy way to add registration column. Thanks alot for sharing it! Just one tiny little thing I have noticed; at the part for removing a column there is an “s” missing:
unset( $columns[‘posts’] );
Apart from that it works perfect! :)
Thank you :)
Hello Misha,
Thank you for the solution, would you please give us a hint how to make a sortable column for custom field ?
Thank you in advance.
Hello Jenz,
there are just two steps to implement it:
Step 1. Filter manage_{screen id}_sortable_columns
So, for users page, screen ID will be
users
.To make column sortable you just have to add one more array value there, ok, just like in the post above.
For default columns like registration date, implementing the first step is more than enough.
Step 2. pre_get_users hook
Well, I had no time to test it, but it supposed to work just like
pre_get_posts
filter. So, in theory the code will look like this:Please let me know if it works :)
Thank you so much, it works like charm.
Hello, Misha nice tutorial. Thanks
How can make the column decs by default. So that newly registered user can be seen top most by default.
Hello Hasan,
Would you like the column to be sortable as well?
Nice tuto Misha, thanks a lot!!
This column appears correctly but in my site the data is empty. Do you know what the reason may be?
Welcome ๐
Did I understand correctly โ the registration date isn’t displayed, is it?
Yes, the column title appears but the field with the date is empty.
Thanks a lot!
Hey,
I could try to help you with the code, just contact me.
OMG! I had an error in my own code. Now I see it correctly. Thanks a lot!!!
Thank you so much. I used the snipped and it worked like a charm.
Thank you for the tut.
Thank you !!!
Is it possible to sort by default Registeration Date DESC when I’m visiting the User section on admin ?
Thank you
Hmmm… try this snippet.
Perfect Misha, thank you !
in what file do I add this code…. and, can I still do it with the latest version of WordPress?
functions.php
of your current theme would be OK, but better โย child theme, and better โ custom plugin. Yes, it works perfectly with the latest WordPress.Thank you so much for this, Misha – I thought I was going to have to install a plugin which is crazy for what should be standard.
Hey Arthur,
Always welcome ๐
Really useful – thanks Misha.
Just a quick note to say Thank you. Works great.
How do we add the “at” to the time so that it displays like this: 10th of february 2019 at 09:30
And not just 10th aug 09:30
Thanks for an awesome snippet by the way!
Thank you! Works great :)
Hello,
This is my first comment on your site.
Very nice job and well documented.
Is it possible to sort on multiple columns. For example sorting first on a “Pickup Location” column then on the “Pickup date” ?
Nice work.
How could i display the date format in german?
Thanks!
Sorry, I do not know what is german date format, do you mean “dd.mm.yyyy” ?
Thank you for sharing this very simple solution!
Thank you so much.
I just want to said big thank you
You’re welcome! ๐๐ผ
Hi,
The registration and can be sorted before but for some reason, it can only show the registration but it can’t be sorted. Do you know the reason?
Kind Regards
hi, sorry, forget my comment earlier. Your code works like a charm. Thanks
Works like a charm. Thank you.
Perfect and Thanks. I have used a lot of your Snippets to my Blogs and Woo-commerce sites and they all work Perfect. Sweet!
Thank you!