Modifying the members search by adding own filter
- 
		Hi! I’m trying to add my own SQL query to the “search_users” function without touching the core. 
 The function can be found in bp-core/bp-core-classes.php233 function search_users( $search_terms, $limit = null, $page = 1 ) { 
 234 global $wpdb, $bp;
 235
 236 if ( !function_exists(‘xprofile_install’) )
 237 return BP_Core_User::get_active_users( $limit, $page );
 238
 239 if ( $limit && $page )
 240 $pag_sql = $wpdb->prepare( ” LIMIT %d, %d”, intval( ( $page – 1 ) * $limit), intval( $limit ) );
 241
 242 like_escape($search_terms);
 243
 244 $total_users_sql = apply_filters( ‘bp_core_search_users_count_sql’, “SELECT DISTINCT count(u.ID) as user_id FROM ” . CUSTOM_USER_TABLE . ” u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE pd.value LIKE ‘%%$search_terms%%’ ORDER BY pd.value ASC”, $search_terms );
 245 $paged_users_sql = apply_filters( ‘bp_core_search_users_sql’, “SELECT DISTINCT u.ID as user_id FROM ” . CUSTOM_USER_TABLE . ” u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE pd.value LIKE ‘%%$search_terms%%’ ORDER BY pd.value ASC{$pag_sql}”, $search_terms, $pag_sql );
 246
 247 $total_users = $wpdb->get_var( $total_users_sql );
 248 $paged_users = $wpdb->get_results( $paged_users_sql );
 249
 250 return array( ‘users’ => $paged_users, ‘total’ => $total_users );
 251 }Thus I’ve tried applying my query by putting this code in my bp-custom.php: function mysql_bp_core_search_users_sql() { 
 global $wpdb;
 return $wpdb->prepare( “SELECT DISTINCT u.ID as user_id FROM ” . CUSTOM_USER_TABLE . ” u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE u.spam = 0 AND u.deleted = 0 AND u.user_status = 0 AND pd.value AND pd.field_id != 10 LIKE ‘%%$search_terms%%’ ORDER BY pd.value ASC{$pag_sql}”, $search_terms, $pag_sql );
 }
 add_filter( “bp_core_search_users_sql”, “mysql_bp_core_search_users_sql” );But it does not affect the search! 
 What is my mistake?
 TiA
- The topic ‘Modifying the members search by adding own filter’ is closed to new replies.