Sort Users by Date Added

I added some columns to the admin user browse table. The columns contain user data from other database tables, like ‘added’ from ‘user activations’.

Now I’d like to enable sorting on these columns. I’ve been chasing my tail with this for a little while, and I’d welcome suggestions. How can I do this?


Just adding a note. I know users are sorted by identifier (so by date added) by default. I’m mostly curious about sorting by fields from a table other than ‘users’, and I mentioned date added as an example.

You’d need a plugin that uses the users_browse_sql hook to add the SQL for the sorting. If you have been creating those columns along the same pattern as the others, you’ll just have to handle the data from other columns in the sort_field data passed along in the request with a join to the other table.

The Guest Users plugin does that, at least for date added, so copying that code is a good starting place.

Excellent. Thanks Patrick!

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.