You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the situation where:
a) a user can belong to multiple groups
b) an entry with this User Group Field can have many user groups checked
c) the checked groups in b) dictate which user groups can see that entry
I'd like to be able to retrieve, via an element query, entries that the current user is allowed to see. Given the example in the docs:
{% set userGroup = craft.app.userGroups.getGroupByHandle('myUserGroup') %}
{% set articlesQuery = craft.entries()
.section("news")
.userGroupFieldHandle( userGroup.uid )
.orderBy("postDate DESC")
.limit(6)
%}
This doesn't appear to work if the User Group Field uses checkboxes (at least, an element query doesn't return anything even when passing a valid UID as a basic string as a parameter in the element query like the example above).
Is there anything I can pass to the User Group Field in an element query, or a way to form the query in such a way that it'll do what I want? I've tried pasting in valid UIDs as a string and as an array of strings to at least see if it's possible, even before working out the user's permission groups UIDs to use those instead (Sticking in canAccess would be nice, but...)
Essentially, I need a "get me all the entries in section 'news' that have the intersection of the user's groups and the entry's checked values in the User Groups field".
The text was updated successfully, but these errors were encountered:
Sorry Josh, completely forgot to add version!!
Yes, Craft 5.6.6 (User Group Field 4.0.0).
I've updated the dependency and this seems to be working a treat. As per standard element queries, it's possible to pass in an array of group UIDs if the user belongs to many.
Great job, thanks for a really quick answer and fix. Appreciated!
Question
Given the situation where:
a) a user can belong to multiple groups
b) an entry with this User Group Field can have many user groups checked
c) the checked groups in b) dictate which user groups can see that entry
I'd like to be able to retrieve, via an element query, entries that the current user is allowed to see. Given the example in the docs:
This doesn't appear to work if the User Group Field uses checkboxes (at least, an element query doesn't return anything even when passing a valid UID as a basic string as a parameter in the element query like the example above).
Is there anything I can pass to the User Group Field in an element query, or a way to form the query in such a way that it'll do what I want? I've tried pasting in valid UIDs as a string and as an array of strings to at least see if it's possible, even before working out the user's permission groups UIDs to use those instead (Sticking in
canAccess
would be nice, but...)Essentially, I need a "get me all the entries in section 'news' that have the intersection of the user's groups and the entry's checked values in the User Groups field".
The text was updated successfully, but these errors were encountered: