# MemberPress + BuddyPress: Add Members to a Group

> Adds MemberPress members to a BuddyPress group for their membership when they pay, giving each tier its own private community space.

- Type: PHP
- Runs: Run everywhere
- Category: [Memberships](https://wpide.com/library/category/memberships/)
- Requires: MemberPress
- Tags: memberpress, buddypress, groups
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/memberpress-buddypress-group-join/

## Code

```php
if ( ! class_exists( 'MeprUser' ) || ! function_exists( 'groups_join_group' ) ) {
    return;
}

// Membership ID => BuddyPress group ID.
$wpide_mepr_bp_groups = array(
    123 => 2,
);

add_action( 'mepr-event-transaction-completed', function ( $event ) use ( $wpide_mepr_bp_groups ) {
    $txn      = $event->get_data();
    $group_id = $wpide_mepr_bp_groups[ (int) $txn->product_id ] ?? 0;

    if ( $group_id && ! groups_is_user_member( (int) $txn->user_id, $group_id ) ) {
        groups_join_group( $group_id, (int) $txn->user_id );
    }
} );
```

## Notes

Map membership IDs to BuddyPress group IDs. Members are not removed from groups automatically when they leave.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "MemberPress + BuddyPress: Add Members to a Group" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
