WordPress admin user search by name

When we search user from wordpress dashboard (Users > All Users) we can search with username and email address. But we can’t search with first name or last name or both. So, what if we want to use search by name? You can use the following code snippet for that. You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. [php] add_action(‘pre_user_query’,’alter_pre_user_query’); function alter_pre_user_query($user_search) { global $wpdb; $vars = $user_search->query_vars; if (!is_null($vars[‘search’])) { $search = preg_replace(‘/^*/’,”,$vars[‘search’]); $search = preg_replace(‘/*$/’,”,$search); $user_search->query_from .= ” INNER JOIN {$wpdb->usermeta} […]

Continue Reading

You may also like