Monthly Archives: May 2011

Search Admin User List on First and Last Names

This code requires WordPress 3.1 and above!

Add this function and hook to your functions.php to enable searching the first_name and last_name fields on the Admin Users page.  Also enables sorting by lastname, firstname using the special ‘byname:’ prefix to the sort text.

By default, the ‘Search Users’ box on the Admin Users page only checks fields present in wp_users.  This function uses the pre_user_query hook to add wp_usermeta rows having the meta_key of either ‘first_name’ or ‘last_name’ to the FROM clause.  Then, it modifies the WHERE clause to add the check for the search term.

Here is the code: Continue reading