Group::list_( $args,  $assoc_args )

Get a list of groups.


Description Description

Top ↑

OPTIONS OPTIONS

[–=] : One or more parameters to pass. See groups_get_groups()

[–fields=] : Fields to display.

[–user-id=] : Limit results to groups of which a specific user is a member. Accepts either a user_login or a numeric ID.

Top ↑

[–orderby=] : Sort order for results. [–orderby=] : Sort order for results.

default: name options:

  • name
  • date_created
  • last_activity
  • total_member_count

Top ↑

[–order=] : Whether to sort results ascending or descending. [–order=] : Whether to sort results ascending or descending.

default: ASC options:

  • ASC
  • DESC

Top ↑

[–format=] : Render output in a particular format. [–format=] : Render output in a particular format.

default: table options:

Top ↑

[–count=] : Number of group items to list. [–count=] : Number of group items to list.

Top ↑

default: 50 default: 50

Top ↑

EXAMPLES EXAMPLES

$ wp bp group list --format=ids
$ wp bp group list --format=count
$ wp bp group list --user-id=123
$ wp bp group list --user-id=user_login --format=ids

Source Source

File: cli/src/group.php

	public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
		$formatter  = $this->get_formatter( $assoc_args );
		$query_args = wp_parse_args(
			$assoc_args,
			array(
				'count'       => 50,
				'show_hidden' => true,
				'orderby'     => $assoc_args['orderby'],
				'order'       => $assoc_args['order'],
				'per_page'    => $assoc_args['count'],
			)
		);

		if ( isset( $assoc_args['user-id'] ) ) {
			$user                  = $this->get_user_id_from_identifier( $assoc_args['user-id'] );
			$query_args['user_id'] = $user->ID;
		}

		$query_args = self::process_csv_arguments_to_arrays( $query_args );

		// If count or ids, no need for group objects.
		if ( in_array( $formatter->format, array( 'ids', 'count' ), true ) ) {
			$query_args['fields'] = 'ids';
		}

		$groups = groups_get_groups( $query_args );
		if ( empty( $groups['groups'] ) ) {
			WP_CLI::error( 'No groups found.' );
		}

		if ( 'ids' === $formatter->format ) {
			echo implode( ' ', $groups['groups'] );
		} elseif ( 'count' === $formatter->format ) {
			$formatter->display_items( $groups['total'] );
		} else {
			$formatter->display_items( $groups['groups'] );
		}
	}


Top ↑

User Contributed Notes User Contributed Notes

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