Get User Group Name (for string comparison)
-
Hi,
I’m trying to set up a private gallery for clients. I’m using UAM to group users…each user gets one group only…and what I want to do in my page template is show a loop of images that are given an attachment_category (via Media Library Assistant plugin) that would match the name of the UAM group.
So, I’m basically just trying to get a string which is the exact name of the group. And then I will pass this into my WP_Query as the attachment_category.
I have grabbed some code from this forum (or maybe it was a stackoverflow link) that will allow me to grab $userGroupsForUser variable that would supposedly be what I’m aiming for. However, when I echo out $userGroupsForUser, I get an array, not a string. When I var_dump this, it’s a huge, huge array with a lot of info.
How to just grab this group name?
Here’s the code I’m using:
global $userAccessManager; if (isset($userAccessManager)) { $userId = get_current_user_id(); echo $userId; $uamAccessHandler = $userAccessManager->getAccessHandler(); $userGroupsForUser = $uamAccessHandler->getUserGroupsForObject('_user_', $userId); $attachment_category = $userGroupsForUser; }
How can I adapt this so $attachment_category is just a single group name, that I can then pass into my WP_Query?
Thanks for any help! And for the useful plugin.
- The topic ‘Get User Group Name (for string comparison)’ is closed to new replies.