Skip to:
Content
Pages
Categories
Search
Top
Bottom

friends_check_friendships not working


  • mattnetusa
    Participant

    @mattnetusa

    This is returning nothing or null. I thought it was supposed to return true or false. I am obviously using it with wrong syntax or something.

    friends_check_friendships(bp_loggedin_user_id(), bp_displayed_user_id()) is not returning anything

    I simply want to return the value true or false to a page for each user in an unordered list. I’m using ‘allow php in html’ and it works everywhere else, but not for this? Maybe it’s my syntax for calling the function is wrong? Any help would be great or beter yet if here is an easier way to check if a user_id given is a friend or not.

    WP – 3.8
    BP – 1.9

    Welcome to MatterialX!

Viewing 5 replies - 1 through 5 (of 5 total)

  • shanebp
    Moderator

    @shanebp

    If you’re not on the members page or a profile page, I don’t think bp_displayed_user_id() will work.

    You need to get all the member ids and then loop thru them, something like:
    friends_check_friendships(bp_loggedin_user_id(), $ids[$i])

    You’re doing this on a custom WP page?
    Rather than use ‘allow php in html’, you should create a template and assign it to that page.

    You know that /members/mattnetusa/friends/ lists your friends ?


    mattnetusa
    Participant

    @mattnetusa

    Thanks for your response! okay maybe I am stating this wrong. I have a list of entries showing various user ids as one of the fields. In the next field I simply want to show are these entries from a friend or not so that I can filter them to only show me entries from my friends. Does that make sense. I thought the purpose of the friends_check_friendships function was to compare to user ids to see if their is a relationship between them and return ‘true’ or ‘false’? Also, are the user ids in buddypress friendships the same user ids in wordpress users without buddypress? For instance the two I am comparing are user_id=1 and user_id=2, so in the function, it should result in friends_check_friendships(1,2) = true right?


    shanebp
    Moderator

    @shanebp

    Try
    bp_is_friend( $user_id )

    It will check to see if the logged_in user is a friend of $user_id

    Returns – ‘is_friend’, ‘not_friends’, ‘pending’.


    mattnetusa
    Participant

    @mattnetusa

    Thanks. okay so I can get that working now to give me a result at least, but I have set it up in my functions.php file as a shortcode that I can call, but how do I feed it the variable of the $user_id when using shortcode? like [shortcodename id=2]?

    I have added the line add_shortcode('shortcodename', 'bp_is_friend'); to functions.php and calling it with [shortcodename].

    Again thanks for the help…feellike I’m finally getting somewhere towards my goal…


    mattnetusa
    Participant

    @mattnetusa

    add_shortcode('mx-check-if-friends','mx_friends_check_friendship');
    function mx_friends_check_friendship( $atts ){
    	extract(shortcode_atts(array(
    		'user_id' => '',
    		'possible_friend_id' => '',
    	), $atts ) );
    	return friends_check_friendship( $user_id, $possible_friend_id );
    }

    OK, I’m not sure if this is exactly correct but it is returning a 1 if friends and a blank if not…basically wrote a shortcode that points to a function that I can provide variables in that in turn then calls the friends_check_friendship function. Anything blatantly wrong with this method?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘friends_check_friendships not working’ is closed to new replies.
Skip to toolbar