XF 2.1 Need to fetch users from certain secondary usergroup

Hi,

I need to get the list of users that are in a particular secondary usergroup, preferably if possible in REST API or in PHP.

Any help is much appreciated; thank you!
 
In that case you would need to load the finder.

PHP:
$memberFinder = \XF::finder('XF:User');
$secondaryGroupMembers = $memberFinder->where('secondary_group_ids', '2')->fetch();

Then just loop it through a foreach.

I'm still exploring REST API in XF so can't give much on that yet.
 
In that case you would need to load the finder.

PHP:
$memberFinder = \XF::finder('XF:User');
$secondaryGroupMembers = $memberFinder->where('secondary_group_ids', '2')->fetch();

Then just loop it through a foreach.

I'm still exploring REST API in XF so can't give much on that yet.
Thank you for your help!

I'm not so familiar with PHP; am I doing something wrong here?

PHP:
$memberFinder = \XF::finder('XF:User');
$secondaryGroupMembers = $memberFinder->where('secondary_group_ids', '2')->fetch();

foreach($secondaryGroupMembers as $result) {
    echo $result;
}
 
Code:
$finder = $this->finder('XF:User');
$inSet = $finder->expression("FIND_IN_SET(3, secondary_group_ids)");
$finder->where($inSet);
$users = $finder->fetch();

foreach ($users as $user)
{
   echo 'User name: ' . $user->username . '<br />';
}

Change the 3 to whatever user group ID you want to have the list for.
 
Code:
$finder = $this->finder('XF:User');
$inSet = $finder->expression("FIND_IN_SET(3, secondary_group_ids)");
$finder->where($inSet);
$users = $finder->fetch();

foreach ($users as $user)
{
   echo 'User name: ' . $user->username . '<br />';
}

Change the 3 to whatever user group ID you want to have the list for.
Thanks a lot Snog! Works great! :D
 
Code:
$finder = $this->finder('XF:User');
$inSet = $finder->expression("FIND_IN_SET(3, secondary_group_ids)");
$finder->where($inSet);
$users = $finder->fetch();

foreach ($users as $user)
{
   echo 'User name: ' . $user->username . '<br />';
}

Change the 3 to whatever user group ID you want to have the list for.
Thank you so much @Snog !
 
Back
Top Bottom