DesignMe recently upgraded a website that uses our developers PRO version of s2Member. Part of the project was creating a directory using the plugin’s Member List function. However, the sort option was for display name … and the display name was set to different formats. I needed it to display and sort by last name. After spending a long while looking for solutions, I found this bit of code which forces a the format of the displayname to LAST NAME/FIRST NAME:
(place this in your function.php file)
//Sets the user's display name (always) to first name last name, when it's avail.
add_action ('admin_head','make_display_name_f_name_last_name');
function make_display_name_f_name_last_name(){
$users = get_users(array('fields'=>'all'));
foreach($users as $user){
$user = get_userdata($user->ID);
$display_name = $user->last_name . ", " . $user->first_name;
if($display_name!=' ') wp_update_user( array ('ID' => $user->ID, 'display_name' => $display_name) );
else wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
if($user->display_name == '')
wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
}
}
Happy Coding!



Just want give my 2 cents on this:
The above code when implemented slowed my Admin Dashboard to a crawl (only the backend, frontend was fine).
Using Query Monitor, I realized that this code was the culprit as it accounted for more than 14s worth of query time.
If your website has a large number of members like mine, this is what will happen to you too.
I found an alternative method that works just as well without the load.
http://geektamin.com/blog/533/why-update_user_meta-display_name-doesnt-work-and-how-to-use-pre_user_display_name-instead/
Cheers