Reply To: Sorting member directory by display name not username
I have something like the following for creating a custom sort. You can likely use the same thing for editing an existing sort:
add_action( 'bp_pre_user_query', 'custom_pro_pre_user_query' );
function custom_pro_pre_user_query( $BP_User_Query ) {
// Only run this if one of our custom options is selected
if ( in_array( $BP_User_Query->query_vars['type'], array( '/*Change this to the value of the Option in the sort drop-down needed*/' ) ) ) {
global $wpdb;
// Adjust SELECT
$BP_User_Query->uid_clauses['select'] = "
select distinct um.user_id, um.meta_value as latitude, um2.meta_value as longitude
from wp_usermeta as um
left join wp_usermeta as um2 on um.user_id=um2.user_id and um2.meta_key = 'geo_long'
";
// Adjust WHERE
$BP_User_Query->uid_clauses['where'] = "WHERE um.meta_key='geo_lat'";
// Adjust ORDER
$BP_User_Query->uid_clauses['order'] = ( $BP_User_Query->query_vars['type'] == 'points-asc' ) ? 'ASC' : 'DESC';
echo '<script>console.log("'.$BP_User_Query->uid_clauses['where'].'");</script>';
}
}
I haven’t tested it for what you are asking, but I believe it should work. You’ll have to edit the MySQL query itself obviously to return the results you want. By the way I found this code from the MyCred plugin Author, Gabriel Merovingi (may have gotten spelling of last name wrong)