How to list friends of a member on main page?
-
For a while now I have been playing around with Buddypress, and now I actually would like to list the friends of a logged in member on the main page.
For example when I log in with my user-account, I want maybe 12 random friends of mine to appear in a sidebar, about the same way as we can see our friends in our profile-page.
– Is there any way I can do this with the functions we allready have?
Thanks in advance!
-
yes
it is just sql…
line 260 from bp-friends-classes.php Version 813 (has not been adjusted for new $bp changes)
function get_random_online_friends( $user_id, $total_friends = 5 ) {
global $wpdb, $bp;
$sql = $wpdb->prepare( “SELECT u.friend_user_id, u.initiator_user_id FROM {$wpdb->base_prefix}usermeta um LEFT JOIN ” . $bp . ” u ON u.ID = um.user_id WHERE um.meta_key = ‘last_activity’ AND (u.friend_user_id = %d || u.initiator_user_id = %d) && u.is_confirmed = 1 AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 5 MINUTE ) >= NOW() ORDER BY rand() LIMIT %d”, $user_id, $user_id, $total_friends );
$results = $wpdb->get_results($sql);
for ( $i = 0; $i < count($results); $i++ ) {
$fids[] = ( $results[$i]->friend_user_id == $user_id ) ? $results[$i]->initiator_user_id : $results[$i]->friend_user_id;
}
// remove duplicates
if ( count($fids) > 0 )
return array_flip(array_flip($fids));
else
return false;
}
reference: get_online_users, in bp-core-classes
hi!
maybe i understood this wrong. fishbowl81 described a possibilty for a “Friends Online” function/widget, right?
o.k. if thats right, i am happy because that is what i am searching. the problem now seems to be, that my knowledge isn’t enough to realize it. i need some help!
taking the function like posted here leads to an error. like fishbowl mentioned $bp changes, therefor i changed: ” . $bp . ” first to: ” . $bp->friends->table_name . ” second to: {$bp->friends->table_name}. in both cases no error, but it doesn’t seem to work the i way i want, showing recently active friends, instead it shows the friend not active for weeks.
o.k., i don’t have a clue how sql works. so i can not figure out what’s wrong. maybe it’s something very simple… if someone would take a look at this problem i would be very thankful!
I wanted to add follow functions same like twitter in my BuddyPress site , I wanted to remove friendship function completely , I don’t want to use any plugins , I wanted to change core file , where should I edit ?? Plz help
- The topic ‘How to list friends of a member on main page?’ is closed to new replies.