Skip to:

[Resolved] Showing posts by groups

  • kypto



    is it possible to show posts that are written just by users in specific group?

    for example i will select group “Group1” which has 3 users in it and it will show me all posts just from that 3 users.


Viewing 5 replies - 1 through 5 (of 5 total)
  • Sure. You’ll need a to make a loop in which you get the ids of the group members and then create a query to fetch those posts.

    For getting group member ids, look at:
    groups_get_group_members( $args = array( $group_id => # ) )

    For the query by author ids:



    thx, but could you help me with that loop? i understand that query thinq, however im not very good at java and cant figure out how to make the loop for members ids work. the goal should be to get the string like “id,id,id” (in order to use it at the query – author=string),but i dont know how to get it from that goups_get_group_member function.

    and one more thing, in documentation there is that the group_id is taken from currect groud (if i get it right :D), but i need it to be from any group i choose.



    * php not java (it was late and i was sleepy :D)



    ok, ignore my last post. i just figured out that you can obtain the members ids with:

    $authors = BP_Groups_Member::get_group_member_ids (ID_OF_GROUP_YOU_WANT);

    then i was trying to turn that array into string and put it into query by authors, but it seems not to work since its supposed to be used with int value.

    i was trying something like this:

    $authorsgroup = implode(',', $authors);
    $posts = "'" . "author=" . $authorsgroup . "'";
    $the_query = new WP_Query( $posts );

    …no luck…

    $authorsgroup = implode(',', $authors);
    $the_query = new WP_Query( 'author='$authorsgroup'' );

    … no luck …


    have you got some idea how to put that ids into the query?



    ok, i got it 🙂 i got the right answer sooner, but while i was testing it i chose wrong group so i thought it was wrong. so the right code will be something like this:

    $authors = BP_Groups_Member::get_group_member_ids (ID_OF_GROUP_YOU_WANT);
    ////////// get the ids of members of the group you chose /////////
    unset ($authors[0]);
    $authorsid = implode(',', $authors);
    ////////// get rid of the first element in the array "authors" and then make string "authorsid" from that array. /////////
    $the_query = new WP_Query( 'author='.$authorsid);
    ////////// make the query based on authors with the id string parameter /////////
    ///////// then you make simple post loop, for example: /////////
    if ( $the_query->have_posts() ) {
    echo '<ul class="news-posts">';
    while ( $the_query->have_posts() ) {
    echo '<li>' . get_the_title() . '</li>';
    echo '</ul>';
    } else {}
    /* Restore original Post Data */
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Showing posts by groups’ is closed to new replies.
Skip to toolbar