Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 21st, 2010  |  syntax: None  |  size: 1.18 KB  |  views: 667  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function ray_bp_autocomplete_list($friends, $filter, $limit) {
  2.         global $wpdb, $bp;
  3.  
  4.         $filter = like_escape( $wpdb->escape( $filter ) );
  5.         $page = 1;
  6.  
  7.         if ( $limit && $page )
  8.                 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
  9.  
  10.         // filter the user_ids based on the search criteria.
  11.         if ( function_exists('xprofile_install') ) {
  12.                 $sql = "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE value LIKE '$filter%%' {$pag_sql}";
  13.                 $total_sql = "SELECT COUNT(DISTINCT user_id) FROM {$bp->profile->table_name_data} WHERE value LIKE '$filter%%'";
  14.         } else {
  15.                 $sql = "SELECT DISTINCT user_id FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'nickname' AND meta_value LIKE '$filter%%' {$pag_sql}";
  16.                 $total_sql = "SELECT COUNT(DISTINCT user_id) FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'nickname' AND meta_value LIKE '$filter%%'";
  17.         }
  18.  
  19.         $filtered_ids = $wpdb->get_col($sql);
  20.         $total_ids = $wpdb->get_var($total_sql);
  21.  
  22.         if ( !$filtered_ids )
  23.                 return false;
  24.  
  25.         return array( 'friends' => $filtered_ids, 'total' => (int)$total_ids );
  26. }
  27. add_filter( 'bp_friends_autocomplete_list', 'ray_bp_autocomplete_list', 1, 3 );