Support » Plugin: Pods - Custom Content Types and Fields » Show / Display list of Users by role

  • Resolved rob0m

    (@rob0m)


    Hello pods peeps,
    Pods is great. Thanks for it and all these support docs.
    However, I wonder if you can help please.

    My aim:
    I would like to display a list of Users’ names, limited to those with a particular role. In theory this should be as simple as something like:

    [pods name="User" where ="role = 'customer' " template = "Display Customers template" limit= -1]
    Or something like that.

    I understand now (am not a developer) – from days of digging and reading of the links below; watching the whole video (Jim/Scott/Josh on Finding Your Way in Pods) etc.that its a SQL thing but still lost.

    So,
    A) I’ve Extended Users

    But can’t get a Where query to work.

    What’s weird to me is that ‘role’ or ‘roles’ does not really seem to be a thing – EXCEPT that in a Pods template I can successfully do:

    {@display_name} {@roles}

    And a role (singular) will display with this template. I do not have to tell pods where to find this ‘roles’ field it seems. It just works.

    But try to use a where query to limit result to certain roles only and this ‘role’ or ‘roles’ field and does not work – or is not recognised.

    Despite following the links and references below
    Link 4) is the closest but even still, I can’t make it work.

    B) I’ve created a relationship field in the (Extended) User pod to WP Objects. I’ve tried relating to both the “User Roles” and “User Capabilities” WP Objects on different attempts. I labelled that relationship field ‘site_user_role’ but get no results with that.

    I’ve even taken Josh’s advice from the Finding your way in Pods video (I’m telling you I watched the whole thing!!) about looking at the structure of the table using PhP My Admin. I can see that in the wpnd_usermeta table (mine is prefixed with that wpnd_ ) I can see the array wpnd_capabilities, which links these capabilities, as with all the other usermeta via a User_ID / meta_key and meta_value. I don’t know how to get to it with pods/SQL WHERE query though.

    In looking at the table I recognise that the _capabilities meta_value is an array, so I tried:
    Where = “roles IN ‘customer’ ” …and LIKE
    Also I tried, instead of roles…:
    * role
    * wpnd_capabilities
    * site_user_role (my label for the relationship field)
    etc.

    So what is going wrong for me here?

    I’ve seen and tried to follow solutions like in link 4) below, which is the same as my request but had no luck understanding the solution that the poster got back from IRC – which he kindly posted back on the forum.

    I’ve also studied the table on the pods find page to no avail.

    Upshot:
    How do I reference / query / find results by User roles here?

    If Pods can see {@roles} in a Pods template, without having to tell it where ‘roles’ is, why can’t ‘roles’ be used in a Where query in a shortcode (or in Elementor) which has the Where field available in the pods widget.

    Or, what prefixes, affixes etc must be used to access this role / capabilities array in a WHERE=??

    Is there a lot more to link 4) below, that I am missing?
    I have tried:
    – creating a whole new pod called (Credits),
    – linking it to User (extended)
    but it’s not clear to me how to get it related it properly or how to get the right details (all I really want is display_name).

    What do you think?

    Thanks very much in advance.
    Rob

    I am thinking it has to be simple.
    I also notice a few people asking the same question of various times of the life of pods but some of the answers are old – when pods accepted php in templates and stuff.

    Some of the links and references I’ve been studying

    1) https://pods.io/docs/code/pods/find/

    2) https://codex.wordpress.org/Class_Reference/WP_User_Query

    3) https://pods.io/tutorials/using-pods-create-user-directory/create-user-directory-step-6/
    https://codex.wordpress.org/Function_Reference/get_users

    The closest is
    4) https://pods.io/forums/topic/filter-user-relationship-field-by-role/

    • This topic was modified 4 months, 1 week ago by  rob0m.
    • This topic was modified 4 months, 1 week ago by  rob0m.
    • This topic was modified 4 months, 1 week ago by  rob0m.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Actually, on reflection, it’s clear that I am confused. The 4th link is not the closest. It’s really a User Query I think I want.

    Essentially, in English is:

    -> list the names of all users with these roles.

    Can anyone translate that into Pod please?

    I was thinking I could use it in Elementor then with the pod widget.

    Thanks

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Sorry for the delay, roles is built in to the templating but not for querying. If you would like to query by the user role field, you will need to reference the built-in WordPress meta key for this:

    {prefix}capabilities.meta_value IN ( 'customer', 'etc' )

    In your case, {prefix} is probablywp_, so that would bewp_capabilities.meta_value IN ( ‘customer’, ‘etc’ )`

    If this is a multisite installation, you’ll need to reference the site ID, so on a site that has the ID (blog_id) of 123, the query would be wp_123_capabilities.meta_value IN ( 'customer', 'etc' )

    Hope this helps!

    Plugin Author Jim True

    (@jimtrue)

    Marking this resolved from @sc0ttkclark reply.

    rob0m

    (@rob0m)

    Hi Scott and Jim

    Sorry for even later reply. Just to update really I had a little battle with Scotts guidance but still did not get it to work. I tried over a few days so lost track of what I did. Will post back if I revisit don’t find an alternative. As least for the sake of community learning. Thank you. Apologies again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.