Reply To: Custom Search/Filter based on custom field
I found and added this code to my functions.php within my theme folder – this allows you to sort the members by lastname.
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' );
I then created a custom page template within my theme and pasted the membersloop.php code into that page and made some formatting changes as I only wanted it to affect this one page.
On the line:
<?php if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) : ?>
I added ‘&populate_extras&type=alphabetical’
so the line now shows as:
<?php if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&populate_extras&type=alphabetical' ) ) : ?>
Hope that helps.