Skip to:
Content
Pages
Categories
Search
Top
Bottom

Getting group name from id


  • koendb
    Participant

    @koendb

    Hey,

    I’m trying to add a group with it’s last activities to the sidebar of logged in users.
    Displaying the activities was easy and works great with bp_has_activities().

    Now I want to display the name of the group.
    I can get the ID’s with BP_Groups_Member::get_group_ids( get_current_user_id());
    I select a single ID of that array and try to get the name of the group with:
    $group = groups_get_group( array( ‘group_id’ => $id-of-group) );
    This returns an array with the right keys, but they don’t have values. It also returns empty values when I replace ‘$id-of-group’ with the number of the group I found in phpMyadmin, so that’s not the problem.

    Anything I’m missing or any other way to get the group name?
    Thanks!

    WP:3.8.1
    BP: 1.8.1
    (Website: 24baby.nl)

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

  • shanebp
    Moderator

    @shanebp

    Try this:

    $group_ids =  groups_get_user_groups( bp_loggedin_user_id() ); 
    	
    var_dump( $group_ids["groups"] );
    		
    foreach( $group_ids["groups"] as $id ) { 
      $group = groups_get_group( array( 'group_id' => $id) );	
      echo '<pre>';		
      var_dump( $group );	
      echo '</pre>';
    }

    koendb
    Participant

    @koendb

    Thanks a lot! This really helped!
    But I can’t get the groupname out of the array 🙁
    Tried things like var_dump($group["name"]);
    and
    echo $group["name"];

    I know this isn’t really a bp question, but hope you can help anyway.


    meg@info
    Participant

    @megainfo

    Hi,

    use $group->name

    the result returned by groups_get_group is an Object.


    koendb
    Participant

    @koendb

    Thanks! I got some studying to do… 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting group name from id’ is closed to new replies.
Skip to toolbar