Forums
-
- Forum
- Posts
-
- Installing BuddyPress
- 23,840
- How-to & Troubleshooting
- 129,885
- Creating & Extending
- 25,913
- Requests & Feedback
- 9,553
- Third Party Plugins
- 9,834
- Showcase
- 3,316
- Ideas
- 1,404
- Miscellaneous
- 9,183
-
You don’t show how you call function format_last_name_first.
But this approach is probably better:
// members loop - sort by last name if type== alphabetical
function alphabetize_by_last_name( $bp_user_query ) {
if ( 'alphabetical' == $bp_user_query->query_vars['type'] )
$bp_user_query->uid_clauses['orderby'] = "ORDER BY substring_index(u.display_name, ' ', -1)";
}
add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );
As shown, it will do what your function is doing. You will have to change the ‘-1’ variable, probably to ‘1’. More info.