如何在buddressress中展示共同的朋友

时间:2015-02-13 04:33:50

标签: wordpress buddypress mutual-friendship

如何在buddypress中显示用户的共同朋友我使用了以下代码但是它无法正常工作。我想在用户面前展示共同的朋友。

function get_mutual_firends($wp_logged_user_id, $wp_profile_user_id)
{
global $wpdb, $bp; 
if($wp_logged_user_id==$wp_profile_user_id) return array(); 
$qry = sprintf('SELECT DISTINCT u1.*
FROM '.$wpdb->users.' u1,
(SELECT f1.initiator_user_id,f1.friend_user_id
FROM '.$bp->friends->table_name.' f1
WHERE (f1.initiator_user_id = %1$d
 OR f1.friend_user_id = %1$d)
AND f1.is_confirmed = 1) f1
WHERE (u1.id = f1.initiator_user_id
OR u1.id = f1.friend_user_id)
 AND u1.id <> %1$d
AND EXISTS(SELECT 1
FROM '.$wpdb->users.' u2,
 (SELECT f2.initiator_user_id,f2.friend_user_id
FROM '.$bp->friends->table_name.' f2
WHERE (f2.initiator_user_id = %2$d
OR f2.friend_user_id = %2$d)
AND f2.is_confirmed = 1) f2
WHERE (u2.id = f2.initiator_user_id
OR u2.id = f2.friend_user_id)
AND u2.id <> %2$d
AND u1.id = u2.id)
',$wp_profile_user_id,$wp_logged_user_id);

 return $wpdb->get_results($qry);
}

1 个答案:

答案 0 :(得分:0)

我最近发布了BuddyPress共同朋友的插件(BuddyPress朋友的共同点)。 希望这会对你有所帮助

https://wordpress.org/plugins/mutual-buddies/