Buddypress – How to add group types

It can be useful to have group types sometimes for example, maybe a University might want to have 2 group types for staff and students. So they could have staff groups and student groups ( and a directory for each eg staff would list the staff groups and student groups would list the Student Groups ).

This is easy todo in Buddypress:

function my_bp_custom_group_types() {
    
    bp_groups_register_group_type( 'staff', array(
        'labels' => array(
            'name' => 'Staff groups',
            'singular_name' => 'Staff group'
        ),
 
        // New parameters as of BP 2.7.
        'has_directory' => 'staff',
        'show_in_create_screen' => true,
        'show_in_list' => true,
        'description' => 'some description (maybe better to just wp page content instead of this)',
        'create_screen_checked' => true
    ) );
    
    
    
    
    bp_groups_register_group_type( 'student', array(
        'labels' => array(
            'name' => 'Students',
            'singular_name' => 'Students'
        ),
 
        // New parameters as of BP 2.7.
        'has_directory' => 'students',
        'show_in_create_screen' => true,
        'show_in_list' => true,
        'description' => 'some description (maybe better to just wp page content instead of this)',
        'create_screen_checked' => true
    ) );
    
    
    
    
}

add_action( 'bp_groups_register_group_types', 'my_bp_custom_group_types' );

 

you can then have links like this to view the group directory:

 

/groups/type/staff/

/groups/type/students/

Leave a Comment