BP_XProfile_Group::get_group_ids( array $args = array() )

Gets group IDs, based on passed parameters.


Parameters Parameters

$args

(array) (Optional) Array of optional arguments:

  • 'profile_group_id'
    (int) Limit results to a single profile group. Default false.
  • 'exclude_groups'
    (array) Comma-separated list or array of group IDs to exclude. Default false.
  • 'hide_empty_groups'
    (bool) True to hide groups that don't have any fields. Default: false.

Default value: array()


Top ↑

Return Return

(array)


Source Source

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

	public static function get_group_ids( $args = array() ) {
		global $wpdb;

		$r = array_merge(
			array(
				'profile_group_id'  => false,
				'exclude_groups'    => false,
				'hide_empty_groups' => false,
			),
			$args
		);

		$bp = buddypress();

		if ( ! empty( $r['profile_group_id'] ) ) {
			$where_sql = $wpdb->prepare( 'WHERE g.id = %d', $r['profile_group_id'] );
		} elseif ( $r['exclude_groups'] ) {
			$exclude   = join( ',', wp_parse_id_list( $r['exclude_groups'] ) );
			$where_sql = "WHERE g.id NOT IN ({$exclude})";
		} else {
			$where_sql = '';
		}

		// Include or exclude empty groups.
		if ( ! empty( $r['hide_empty_groups'] ) ) {
			$group_ids_sql = "SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC";
		} else {
			$group_ids_sql = "SELECT DISTINCT g.id FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC";
		}

		$cached = bp_core_get_incremented_cache( $group_ids_sql, 'bp_xprofile_groups' );
		if ( false === $cached ) {
			$group_ids = $wpdb->get_col( $group_ids_sql );
			bp_core_set_incremented_cache( $group_ids_sql, 'bp_xprofile_groups', $group_ids );
		} else {
			$group_ids = $cached;
		}

		return array_map( 'intval', $group_ids );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.