Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to obtain follower ids

  • @iamdev

    Participant

    Is there anyway to obtain all the ids of loggedin user is following i mean is there any similar code like this to check $friend_ids = friends_get_friend_user_ids( bp_loggedin_user_id() ); for followers too

Viewing 8 replies - 1 through 8 (of 8 total)
  • @iamdev

    Participant

    Anyone please help me !

    @venutius

    Moderator

    $following_ids = bp_get_following_ids( array( 'user_id' => $user_id ) );

    @iamdev

    Participant

    Thanks but it is not working what i am trying to do is i want to show post by the user current logged-in user is following
    this is the code but it is not working

    <?php 
    // Run WP_Query
    // change posts_per_page value to limit the number of posts
    $per_page = 8;
    $following_ids = bp_get_following_ids( array( 'user_id' => $user_id ) );
    $args = array(
    	         'author__in' => $following_ids,
    			'posts_per_page' => $per_page,
    			'orderby'		 => 'meta_value',
    			'meta_key'		 => '_post_like_count',
    			'orderby'		 => 'meta_value_num',
    			'order'			 => 'DESC',
    		);                                              
    $query = new WP_Query( $args );
    //begin loop
    while ($query->have_posts()) : $query->the_post(); ?>

    Am i doing something wrong with respect to the argument

    @venutius

    Moderator

    Are you setting the $user_id? Also you are not passing the following id’s into the query, you can use the author parameter for that, you may need to restructure the following id’s into the right format for the query. Not sure what you are doing with the meta query.

    @iamdev

    Participant

    What i want to do is i want to show all the blog post by only those user , the current user is following

    @venutius

    Moderator

    I’d try something like this:

    <?php 
    // Run WP_Query
    // change posts_per_page value to limit the number of posts
    $per_page = 8;
    $following_ids = bp_get_following_ids( array( 'user_id' => $user_id ) );
    $args = array(
    	         'author__in' => $following_ids,
    			'posts_per_page' => $per_page,
    			'author'		 => $following_ids
    		);                                              
    $query = new WP_Query( $args );
    //begin loop
    while ($query->have_posts()) : $query->the_post(); ?>

    @iamdev

    Participant

    @venutius I have tried it is not working

    @iamdev

    Participant

    Finally done we were doing wrong with respect to the $following_ids = bp_get_following_ids( array( 'user_id' => $user_id ) ); rather than passing $user_id we should have passed this bp_loggedin_user_id() but thanks @venutius for your help.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar