function ray_bp_autocomplete_list($friends, $filter, $limit) { global $wpdb, $bp; $filter = like_escape( $wpdb->escape( $filter ) ); $page = 1; if ( $limit && $page ) $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); // filter the user_ids based on the search criteria. if ( function_exists('xprofile_install') ) { $sql = "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE '$filter%%' {$pag_sql}"; $total_sql = "SELECT COUNT(DISTINCT user_id) FROM {$bp->profile->table_name_data} WHERE value LIKE '$filter%%'"; } else { $sql = "SELECT DISTINCT user_id FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'nickname' AND meta_value LIKE '$filter%%' {$pag_sql}"; $total_sql = "SELECT COUNT(DISTINCT user_id) FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'nickname' AND meta_value LIKE '$filter%%'"; } $filtered_ids = $wpdb->get_col($sql); $total_ids = $wpdb->get_var($total_sql); if ( !$filtered_ids ) return false; return array( 'friends' => $filtered_ids, 'total' => (int)$total_ids ); } add_filter( 'bp_friends_autocomplete_list', 'ray_bp_autocomplete_list', 1, 3 );