Support » Plugin: Pods - Custom Content Types and Fields » Using WP_User_Query on Pods fields

  • Resolved Matt Knowles

    (@aestheticdesign)


    After coming across your tutorial at https://docs.pods.io/tutorials/creating-user-directory/step-5-creating-a-list-of-users-and-profile-page/ I decided to follow that and extend the User type rather than create a custom post type. Thanks for that tutorial, it was very helpful.

    For the page I’m working on, I want to be able to select a subset of users, based on a Pod field of Company, which is a related field, to a custom category.

    I tried the following code but I get No users found.

    $users = new WP_User_Query(array(
    ‘meta_key’=>’_pods_company’,
    ‘meta_value’ => ‘C1’,
    ‘orderby’=>’meta_value’,
    ‘fields’=>’all_with_meta’
    ));

    I tried first using ‘company’ for the meta_key, but after that didn’t work, I looked in the database and saw it listed as _pods_company. The tutorial doesn’t provide an example so I’m not sure how to select the records based on Pods field.

    I tried using last_name for meta_key and a valid last name for meta_value and that worked ok. So I’m not sure if I need to do something different if I wan’t to search for a Pods field?

    I tried searching the forum for WP_User_Query and came up empty

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Can you clarify what type of field the Company field is? Is it related to another object or is it a “Simple Relationship” where it’s just a list of text in the field editor?

    Matt Knowles

    (@aestheticdesign)

    Companies is set up as a Custom Taxonomy, just one field, company.

    Values are hierarchical:

    • Chiefs
      • C1
      • C2
      • C3
    • Company 1
    • Company 2
    • Company 3
    • Company 4
    • Probationary
    • This reply was modified 5 months, 3 weeks ago by  Matt Knowles.
    • This reply was modified 5 months, 3 weeks ago by  Matt Knowles.
    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Unfortunately you cannot reference other taxonomy object fields through the meta key/value lookup here. You can reference the Term ID like that though. Try referencing the term ID instead of the term name (C1)

    Plugin Author Jim True

    (@jimtrue)

    Since we’ve not heard back from you on this one, we have to assume the question is resolved so we’re closing this ticket.

    If you’re still having issues, please respond and re-open this ticket or you can join our Slack Chat at https://support.pods.io/chat/

    Thanks!

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