Opened 13 years ago
Closed 13 years ago
#3403 closed defect (bug) (fixed)
Member search doesn't work with alphabetical order
Reported by: | lpryor | Owned by: | |
---|---|---|---|
Milestone: | 1.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Members | Keywords: | |
Cc: |
Description
In the buddypress search, if you select 'Members' and the 'Alphabetical' order, the search is performed only on the member's name (and ignores the other extended profile fields).
This is because of the way the SQL query is constructed in get_users()
in bp-core-classes.php
. If the search is on members, there's a join to the profile data table. If the search is ordered alphabetically, the join is limited to the name rows only.
A fix is to join twice if you need to.
Instead of
if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type ) $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
use
if ( 'alphabetical' == $type ) // separate joins for alphabetical ordering and searching $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id"; if ( $search_terms && function_exists( 'xprofile_install' ) ) // separate joins for alphabetical ordering and searching $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id"; // spd instead of pd
Then pick up the right table in the WHERE clause:
$sql['where_searchterms'] = "AND spd.value LIKE '%%$search_terms%%'"; // now spd.value instead of pd.value
This fix works in version 1.2.9.
Nice catch!