bp_group_has_members( array|string $args = '' )

Initialize a group member query loop.

Description

Parameters

$args

(Optional) An array of optional arguments.

  • 'group_id'
    (int) ID of the group whose members are being queried. Default: current group ID.
  • 'page'
    (int) Page of results to be queried. Default: 1.
  • 'per_page'
    (int) Number of items to return per page of results. Default: 20.
  • 'max'
    (int) Optional. Max number of items to return.
  • 'exclude'
    (array) Optional. Array of user IDs to exclude.
  • 'exclude_admin_mods'
    (bool|int) True (or 1) to exclude admins and mods from results. Default: 1.
  • 'exclude_banned'
    (bool|int) True (or 1) to exclude banned users from results. Default: 1.
  • 'group_role'
    (array) Optional. Array of group roles to include.
  • 'type'
    (string) Optional. Sort order of results. 'last_joined', 'first_joined', or any of the $type params available in BP_User_Query. Default: 'last_joined'.
  • 'search_terms'
    (string) Optional. Search terms to match. Pass an empty string to force-disable search, even in the presence of $_REQUEST['s']. Default: false.

Default value: ''

Return

(bool)

Source

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

function bp_group_has_members( $args = '' ) {
	global $members_template;

	$exclude_admins_mods = 1;

	if ( bp_is_group_members() || bp_is_group_leaders() ) {
		$exclude_admins_mods = 0;
	}

	$group_role = false;
	if ( bp_is_group_leaders() ) {
		$group_role = 'admin,mod';
    }

	/*
	 * Use false as the search_terms default so that BP_User_Query
	 * doesn't add a search clause.
	 */
	$search_terms_default = false;
	$search_query_arg = bp_core_get_component_search_query_arg( 'members' );
	if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
		$search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
	}

	$r = bp_parse_args( $args, array(
		'group_id'            => bp_get_current_group_id(),
		'page'                => 1,
		'per_page'            => 20,
		'max'                 => false,
		'exclude'             => false,
		'exclude_admins_mods' => $exclude_admins_mods,
		'exclude_banned'      => 1,
		'group_role'          => $group_role,
		'search_terms'        => $search_terms_default,
		'type'                => 'last_joined',
	), 'group_has_members' );

	/*
	 * If an empty search_terms string has been passed,
	 * the developer is force-disabling search.
	 */
	if ( '' === $r['search_terms'] ) {
		// Set the search_terms to false for BP_User_Query efficiency.
		$r['search_terms'] = false;
	} elseif ( ! empty( $_REQUEST['s'] ) ) {
		$r['search_terms'] = $_REQUEST['s'];
	}

	$members_template = new BP_Groups_Group_Members_Template( $r );

	/**
	 * Filters whether or not a group member query has members to display.
	 *
	 * @since BuddyPress 1.1.0
	 *
	 * @param bool                             $value            Whether there are members to display.
	 * @param BP_Groups_Group_Members_Template $members_template Object holding the member query results.
	 */
	return apply_filters( 'bp_group_has_members', $members_template->has_members(), $members_template );
}

Changelog

Changelog
Version Description
BuddyPress 1.0.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.