Skip to content

User Group - accessing names and handles. #14942

Closed Answered by brandonkelly
StuartMcD asked this question in Q&A
Discussion options

You must be logged in to vote

You should generally be checking groups based on their handles, rather than IDs. You don’t have any control over user groups’ IDs, and they could change from environment to environment.

Currently recording hard coded user group IDs to be saved with entries that I then use to retrieve based on a users group by searching a text field looking for corresponding ID, all is good the world.

{% set q = 'plainText:3 OR plainText:6' %}

Is this for a user query? If so you can use the group param to pass in the user group handles you care about:

{% set users = craft.users()
  .group(['groupA', 'groupB'])
  .all() %}

In reworking this flow, I'm looking to access, programmatically, the user groups d…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants