Changeset 8087 for trunk/bp-xprofile/bp-xprofile-functions.php
- Timestamp:
- 03/09/2014 01:58:11 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-functions.php
r7885 r8087 455 455 456 456 /** 457 * When search_terms are passed to BP_User_Query, search against xprofile fields. 458 * 459 * @since BuddyPress (2.0.0) 460 * 461 * @param array $sql Clauses in the user_id SQL query. 462 * @param BP_User_Query User query object. 463 */ 464 function bp_xprofile_bp_user_query_search( $sql, BP_User_Query $query ) { 465 global $wpdb; 466 467 if ( empty( $query->query_vars['search_terms'] ) || empty( $sql['where']['search'] ) ) { 468 return $sql; 469 } 470 471 $bp = buddypress(); 472 473 $search_terms_clean = esc_sql( esc_sql( $query->query_vars['search_terms'] ) ); 474 475 // Combine the core search (against wp_users) into a single OR clause 476 // with the xprofile_data search 477 $search_core = $sql['where']['search']; 478 $search_xprofile = "u.{$query->uid_name} IN ( SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE '%{$search_terms_clean}%' )"; 479 $search_combined = "( {$search_xprofile} OR {$search_core} )"; 480 481 $sql['where']['search'] = $search_combined; 482 483 return $sql; 484 } 485 add_action( 'bp_user_query_uid_clauses', 'bp_xprofile_bp_user_query_search', 10, 2 ); 486 487 /** 457 488 * Syncs Xprofile data to the standard built in WordPress profile data. 458 489 *
Note: See TracChangeset
for help on using the changeset viewer.