BP_Groups_Group::get_random( int|null $limit = null, int|null $page = null, int $user_id, string|bool $search_terms = false, bool $populate_extras = true, string|array|bool $exclude = false )

Get a list of random groups.


Use BP_Groups_Group::get() with ‘type’ = ‘random’ instead.



(int|null) (Optional) The max number of results to return. Default: null (no limit).

Default value: null


(int|null) (Optional) The page offset of results to return. Default: null (no limit).

Default value: null


(int) (Optional) If present, groups will be limited to those of which the specified user is a member.


(string|bool) (Optional) Limit groups to those whose name or description field contain the search string.

Default value: false


(bool) (Optional) Whether to fetch extra information about the groups. Default: true.

Default value: true


(string|array|bool) (Optional) Array or comma-separated list of group IDs to exclude from results.

Default value: false



  • 'groups'
    (array) Array of group objects returned by the paginated query.
  • 'total'
    (int) Total count of all groups matching non- paginated query params.


File: bp-groups/classes/class-bp-groups-group.php

	public static function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
		$args = array(
			'type'               => 'random',
			'per_page'           => $limit,
			'page'               => $page,
			'user_id'            => $user_id,
			'search_terms'       => $search_terms,
			'exclude'            => $exclude,

		return BP_Groups_Group::get( $args );


Version Description
BuddyPress 1.6.0 Introduced.


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.