Jump to content

How to select all users who don't have a certain role?


Recommended Posts

Posted

It's easy to select all users who have a certain role. E. g.:

users('roles=foo|bar')

selects all users who have at least one of the roles "foo" or "bar". But I failed doing the opposite: selecting all users who don't have role "foo" or don't have role "bar". I even don't manage the case with only one role. Any ideas?

Posted

Working for me - what's your code? I know you say it's not working even for one role, but remember if for negative selection you want AND and not OR for multiple roles.

Posted
23 hours ago, adrian said:

Working for me - what's your code?

For one role I've tried these four cases, none of them filtered out any user with role "foo":

!roles=foo
roles!=foo
!roles.name=foo
roles.name!=foo

 

Posted (edited)

Hi @FlorianA

Could you post more details related to your piece of code?

I have the impression that it's a little (missing) detail that's making it not working.

Edited by Christophe
Posted

To avoid anything from your template file that might be contributing, can you try this in the Tracy Console panel:

d(users('roles!=foo, roles!=bar')->each("name"));

 

Posted
21 hours ago, adrian said:

To avoid anything from your template file that might be contributing, can you try this in the Tracy Console panel:

Tracy Console? ... <google> ... Tracy Debugger ... Wow! What a wonderful tool! I should have discoverd that earlier. I think it would deserve a place on https://processwire.com/docs/tutorials/  :rolleyes:

Anyway, my problem persists even when trying the command above. My PW version is 3.0.61

  • Like 1
Posted

Glad you made friends with Tracy :)

My PW version is 3.0.61

That might be the problem. I would definitely recommend upgrading to the latest dev version. Many of us are using it on production sites and it will likely become 3.1 stable this week or next.

  • Like 3

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...