Skip to:
Content
Pages
Categories
Search
Top
Bottom

Getting array of all members


  • Snegu
    Participant

    @snegu

    I’m trying to find a function that will return an array of certain xprofile fields from all members, similar to how get_users() works for WordPress user fields. Ideally, I’d also like to select only those members who are attached to a certain role.

    My end goal is to populate a drop-down select menu with the first and last names of all members (from a role).

    It seems like this should be a built in function, but perhaps not?

Viewing 7 replies - 1 through 7 (of 7 total)

  • r-a-y
    Keymaster

    @r-a-y

    If you want to grab multiple xprofile fields from all members, the best way at the moment to accomplish this is to use a direct DB query.

    I was going to recommend the members loop, but you need specific xprofile fields.


    Roger Coathup
    Participant

    @rogercoathup

    If it’s just first and last names for your drop down – you can fetch those from the default WordPress fields / calls.

    Is ‘role’ stored as an xprofile field or are you mapping across to WordPress roles? If the latter, you should also be able to achieve with the built-in WP functions.


    Boris
    Participant

    @travel-junkie

    What do you need the profile fields for? Seems like WP_User_Query would do the job perfectly.
    https://codex.wordpress.org/Class_Reference/WP_User_Query.

    If role is stored as an xprofile field, you might want to look at BP_User_Query. Haven’t used that class yet, but it might do what you want.


    Boris
    Participant

    @travel-junkie

    Also, a select box might not be the best option for what you have in mind. Imagine you’ll get a result of a couple hundred users. Becomes completely unusable. Not sure what your ultimate goal is with that selectbox, but I’d look at other options.


    Snegu
    Participant

    @snegu

    We actually have a pretty limited number of users, who are paired as mentees and mentors. We want each mentor/mentee to be able to select their corresponding mentee/mentor from the list to make sure the spelling is the same. We also want to show linked pairs in another section, which is another headache all to itself.

    The first name and last name are stored as xprofile fields because I needed the privacy and user controls that Buddypress provides. Role is also stored as an xprofile field because we’re using our own defined roles (mentor and mentee).

    Looks like I’m going to have to get deep into the SQL to do this – was just hoping there was something easy I’d missed!


    Snegu
    Participant

    @snegu

    Boris – I was looking at BP_user_query the other day and it looked right up my alley, but do I need to wait till 1.7 to use it? (and any idea when it will be released?)


    Boris
    Participant

    @travel-junkie

    Oh, yeah, forgot that BP_User_Query’ll only land in v1.7. Can’t think of anything else apart from a custom SQL query then. Maybe a good idea to refactor it once you upgraded to BP 1.7, though.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Getting array of all members’ is closed to new replies.
Skip to toolbar