bp_groups_set_group_type( int $group_id, string|array $group_type, bool $append = false )

Set type for a group.

Description

Parameters

$group_id

(Required) ID of the group.

$group_type

(Required) Group type or array of group types to set.

$append

(Optional) True to append this to existing types for group, false to replace. Default: false.

Default value: false

Return

(false|array) $retval See bp_set_object_terms().

Source

File: bp-groups/bp-groups-functions.php

3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
function bp_groups_set_group_type( $group_id, $group_type, $append = false ) {
    // Pass an empty group type to remove group's type.
    if ( ! empty( $group_type ) && is_string( $group_type ) && ! bp_groups_get_group_type_object( $group_type ) ) {
        return false;
    }
 
    // Cast as array.
    $group_type = (array) $group_type;
 
    // Validate group types.
    foreach ( $group_type as $type ) {
        // Remove any invalid group types.
        if ( is_null( bp_groups_get_group_type_object( $type ) ) ) {
            unset( $group_type[ $type ] );
        }
    }
 
    $retval = bp_set_object_terms( $group_id, $group_type, 'bp_group_type', $append );
 
    // Bust the cache if the type has been updated.
    if ( ! is_wp_error( $retval ) ) {
        wp_cache_delete( $group_id, 'bp_groups_group_type' );
 
        /**
         * Fires just after a group type has been changed.
         *
         * @since BuddyPress 2.6.0
         *
         * @param int          $group_id   ID of the group whose group type has been updated.
         * @param string|array $group_type Group type or array of group types.
         * @param bool         $append     Whether the type is being appended to existing types.
         */
        do_action( 'bp_groups_set_group_type', $group_id, $group_type, $append );
    }
 
    return $retval;
}

Changelog

Changelog
Version Description
BuddyPress 2.7.0 $group_type parameter also accepts an array of group types now. BuddyPress 2.7.0 $group_type parameter also accepts an array of group types now.
BuddyPress 2.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.