[buddypress-trac] [BuddyPress] #3403: Member search doesn't work with alphabetical order
buddypress-trac at lists.automattic.com
buddypress-trac at lists.automattic.com
Thu Jul 28 15:49:45 UTC 2011
#3403: Member search doesn't work with alphabetical order
--------------------+-----------------------------
Reporter: lpryor | Owner:
Type: defect | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Core | Version:
Severity: normal | Keywords:
--------------------+-----------------------------
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.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/3403>
BuddyPress <http://buddypress.org/>
BuddyPress
More information about the buddypress-trac
mailing list