Search code examples
phpwordpressbuddypress

Get buddypress group slug by passing its ID


I would like to be able to get a link to a specific buddypress group but by only using the groups ID on a template page.

The admin inputs the groups ID as a custom field on the page, then using this I would like it to be able to generate the groups slug to then create a link to it

Any help is appreciated


Solution

  • To get a buddypress group slug from a group id:

    $group_id = 2;    
    $group = groups_get_group( array( 'group_id' => $group_id ) );
    $slug = $group->slug;