How to get or list all users of specific user group (For Joomla 3.x)
In this article, we will learn: How to get or list all users of specific user group (For Joomla 3.x). This is common need and will be very useful Joomla tip and trick.
Consider following code snippet.
// Get component configuration parameters as set into admin options (define in config.xml file)
$content_params = JComponentHelper::getParams( 'com_bt_property' );
// Get specific parameter, here we are getting user groups set in admin of component options.
$guest_usergroup = $content_params->get( 'guest_usergroup' );
// Import access for Joomla 3.x
jimport( 'joomla.access.access' );
// Loop through all groups set in admin option.
foreach($guest_usergroup as $gu) {
// Get all users of that specific group
$users = JAccess::getUsersByGroup($gu);
foreach($users as $u) {
// Get single user of that specific group and add their mail into array.
$user = JFactory::getUser($u);
$recipient[] =$user->email;
}
}
// Print out user groups set in options and recipent email array list.
echo '<pre>';print_r($guest_usergroup);print_r($recipient);echo '</pre>';
Now you have user details(email in this case), which we used for sending email to these users. And you can user this snippet according to your needs.
Still need help! no problem, feel free to contact us Today