MODx: Get all members of a user group in MODx Revolution.
by kairon - http://www.unchi.co.uk/author/admin/
Get all members of a user group in MODx Revolution. This can been done by accessing the database in the following way.
<?php
$usergroup = 4;
$c = $modx->newQuery('modUser');
$c->innerJoin ('modUserProfile','Profile');
$c->innerJoin ('modUserGroupMember','UserGroupMembers');
$c->innerJoin ('modUserGroup','UserGroup','`UserGroupMembers`.`user_group` = `UserGroup`.`id`');
$c->leftJoin ('modUserGroupRole','UserGroupRole','`UserGroupMembers`.`role` = `UserGroupRole`.`id`');
$c->where(array(
'active' => true,
'UserGroupMembers.user_group' => $usergroup,
'UserGroupMembers.role' => '5',
));
$users = $modx->getCollection('modUser',$c);
foreach($users as $var => $value)
{
// Here you can get profile information e.g. $profile = $user->getOne('Profile');
}