Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Members list oder
Avatar
Patrick DUMOLEYN
Member
sp_UserOfflineSmall Offline
Sep 12, 2014 - 5:07 am

The members list is ordered on the username that is firstname followed by lastname.

How to get the list ordered on the lastname ?

Thanks.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2014 - 5:22 am

Are you referring to the standard members list as generated when you click on the 'members' button in the forum header? 

I am assuming so and if this is the case then that list should be ordered (by default) by the user ID. Can you double check the assertion regarding first name?

andy-signature.png
YELLOW
SWORDFISH
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2014 - 5:31 am

Sorry - my mistake. It is actually, by default, sorted by the users display name.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2014 - 5:44 am

OK - third post before you have had a chance to respond! Bit I have been researching.

Using either the first_name or the last_name data items is actually really rather difficult, cumbersome and a bit of a performance drag. This is because of the really rather nasty way that WordPress chooses to store this data. It can be done but there IS a penalty for doing so. This is why we default to display_name.

So - it can be done using a standard WP filter but it is not recommended. Up to you of course...

andy-signature.png
YELLOW
SWORDFISH
Avatar
Patrick DUMOLEYN
Member
sp_UserOfflineSmall Offline
Sep 12, 2014 - 5:52 am

Thanks for your reply.

What is the code change I have to do to get the members list sorted on last_name ?

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2014 - 6:46 am

Well I am researching and trying but at the moment I am not now even sure it is possible. It really is a hideous way to store data... If I can come up with a solution I will post back here...

And if any SQL guru is reading this and knows if it is possible to JOIN the usermeta table on only the row with a meta_key of 'last_name' then perhaps they can let me know the secret!

andy-signature.png
YELLOW
SWORDFISH
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 12, 2014 - 8:53 am

OK - this might have got it actually. Give it a try..

Add the following to your spFunctions.php file which is in the /templates folder of your Simple:Press theme. You can use the SP theme editor for this of course. It MUST be EXACT so use the raw copy button to copy it...

add_filter('sph_members_list_query', 'my_members_sort');
 function my_members_sort($q) {
 $q->fields .= ', meta_value AS last_name ';
 $q->left_join .= " LEFT JOIN ".SFUSERMETA." ON (".SFUSERMETA.".user_id=".SFMEMBERS.".user_id AND ".SFUSERMETA.".meta_key='last_name')";
 $q->orderby = "usergroup_id ASC, last_name ASC";
 return $q;
 }

See if that does what you want.

Three important things to remember if it DOES work for you.

  1. Expect it to take a little longer to compile and execute
  2. If any of your members have NOT recorded their last_name then they will appear at the top of their user group list because their data will be a null.
  3. You will need to make a child theme or custom theme to avoid this function being lost on future SP updates.

Let me know if it works.

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626