Skip to:
Content

BuddyPress.org

Opened 13 years ago

Closed 13 years ago

#3403 closed defect (bug) (fixed)

Member search doesn't work with alphabetical order

Reported by: lpryor's profile 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.

Change History (2)

#1 @boonebgorges
13 years ago

  • Component changed from Core to Members
  • Milestone changed from Awaiting Review to 1.3

Nice catch!

#2 @boonebgorges
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [4891]) Joins xprofile data field separately for members directory search and for members directory alphabetical sort, to ensure proper search domain. Fixes #3403. Props lpryor

Note: See TracTickets for help on using tickets.