Search code examples
wordpressbuddypress

BuddyPress - How to display posts created by friends?


In WordPress with BuddyPress, how can I display for a user posts (custom post type) that are created by his friends only?

Not as/in activity steam (it's disabled on the site), but as usual loop while(have_posts()):.

Thank you in advance.


Solution

  • Try:

    $friend_ids = friends_get_friend_user_ids( bp_loggedin_user_id() );
    
    if ( ! empty( $friend_ids ) {
    
       $args = array(
           'author__in' => $friend_ids
       ); 
    
       $query = new WP_Query( $args );
    
    }
    

    Adjust $args to include other parameters like post_type. And then create a while loop.