Hi @barodscheff
You can just copy the code from here and paste it in to your page template (say page-poodles.php). You can then go about filtering the returned members as you see fit.
Hi @henrywright
Thats nice, very useful.
Can you kindly say the exact file name where such code can be put? It is not clear to me where I put this code.
Can you please, please say how can I have a Member list page ( or any other page) that lists the Members who are not the logged-in user’s friends?
This means that a logged in user can see only names with “Add friend” buttons by the side of the names.
Thanks
Hi @rosyteddy
I haven’t tried it, but I think it’ll work if you put it in a page template. See here for more info.
Regarding the functionality you want, you’d need to do something like this:
$ids = '1, 2, 5, 33, 43';
if ( bp_has_members( 'exclude=' . $ids ) ) :
Where $ids
is a comma separated list of user IDs who are not friends.
Hi @henrywright
Can you make a plugin out of it 🙂
The main problem is how do I get the $ids
array or whatever.
This code by Brajesh does that
add_action('bp_ajax_querystring','bpdev_exclude_users',20,2);
function bpdev_exclude_users($qs=false,$object=false){
//list of users to exclude
$excluded_user='24,2,3';//comma separated ids of users whom you want to exclude
if($object!='members')//hide for members only
return $qs;
$args=wp_parse_args($qs);
//check if we are listing friends?, do not exclude in this case
if(!empty($args['user_id']))
return $qs;
if(!empty($args['exclude']))
$args['exclude']=$args['exclude'].','.$excluded_user;
else
$args['exclude']=$excluded_user;
$qs=build_query($args);
return $qs;
}
Now all that I want is to $excluded_user = logged in user’s friends. How to do that ?
Thanks
Brajesh seems to have done most of the heavy lifting for what you want. He uses the bp_ajax_querystring
filter, so lets borrow his idea and make our own function to exclude friends from the loop.
function rosyteddy_exclude_users( $querystring = false, $object = false ) {
// Only do this for the members loop.
if ( $object != 'members' )
return $querystring;
// Get an array of friend IDs for the logged-in user.
$ids = friends_get_friend_user_ids( get_current_user_id() );
// Make the array a comma sep list.
$ids = implode( ',', $ids );
$args = wp_parse_args( $querystring );
if ( ! empty( $args['exclude'] ) )
$args['exclude'] = $args['exclude'] . ',' . $ids;
else
$args['exclude'] = $ids;
$querystring = build_query( $args );
return $querystring;
}
add_action( 'bp_ajax_querystring', 'rosyteddy_exclude_users', 20, 2 );
Note: I haven’t tested.
Wow @henrywright you rock!
Cool! My quick test shows its work perfectly.
How to say thank you.
Many, many thanks.
@rosyteddy glad to hear it works! 😀
So, this was the plugin idea I posted sometime ago.
In the above, now if you click “Add friend” some ajax trick should show Friendship Request sent
and the row should fade out, and lower names should come up 🙂
I do not know ajax tricks and am a bad learner 🙂
Thanks a lot once again @henrywright for this great, great snippet.
Additional idea to this : Exclude “Cancel Friendship Request” from this list if its not ajaxified like above to exlude those to whom request has been sent 🙂
Sorry for the nagging 🙂
Thanks always
Thank you @henrywright. Maybe my question wasn’t clear enough.
I’ve already copied the code in a custom template. But how do I call the template? What should be the link target? What do I have to write instead of # to call the template with the filtering (e.g. male members with poodles)
<a href="#">All male members who have poodles</a>
Ok, I solved it with page templates.
Thank you for your help!