bp_xprofile_bp_user_query_search( array $sql, BP_User_Query $query )
When search_terms are passed to BP_User_Query, search against xprofile fields.
Description Description
Parameters Parameters
- $sql
-
(Required) Clauses in the user_id SQL query.
- $query
-
(Required) User query object.
Return Return
(array)
Source Source
File: bp-xprofile/bp-xprofile-functions.php
function bp_xprofile_bp_user_query_search( $sql, BP_User_Query $query ) { global $wpdb; if ( empty( $query->query_vars['search_terms'] ) || empty( $sql['where']['search'] ) ) { return $sql; } $bp = buddypress(); $search_terms_clean = bp_esc_like( wp_kses_normalize_entities( $query->query_vars['search_terms'] ) ); if ( $query->query_vars['search_wildcard'] === 'left' ) { $search_terms_nospace = '%' . $search_terms_clean; $search_terms_space = '%' . $search_terms_clean . ' %'; } elseif ( $query->query_vars['search_wildcard'] === 'right' ) { $search_terms_nospace = $search_terms_clean . '%'; $search_terms_space = '% ' . $search_terms_clean . '%'; } else { $search_terms_nospace = '%' . $search_terms_clean . '%'; $search_terms_space = '%' . $search_terms_clean . '%'; } // Combine the core search (against wp_users) into a single OR clause // with the xprofile_data search. $matched_user_ids = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE %s OR value LIKE %s", $search_terms_nospace, $search_terms_space ) ); if ( ! empty( $matched_user_ids ) ) { $search_core = $sql['where']['search']; $search_combined = " ( u.{$query->uid_name} IN (" . implode(',', $matched_user_ids) . ") OR {$search_core} )"; $sql['where']['search'] = $search_combined; } return $sql; }
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |