Jump to main content Jump to doc navigation

modUser::getUserGroups

Returns the ids of the modUserGroup records joined through modUserGroupMembers for this User. Ids, not names: getUserGroupNames() returns the names for the same membership set.

Results are cached in the session under modx.user.{id}.userGroups and read only when this object is the currently logged in User. Any other User is queried from the database on every call, and the cache entry is rewritten with that result.

Syntax

array getUserGroups ()

Example

foreach ($user->getUserGroups() as $groupId) {
    echo $groupId;
}

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$194 per month—let's make that $500!

Learn more