Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get xprofile field names for different member roles

  • @cplouffe

    Participant

    Hi all,

    This may be an easy question to answer (I’m hopeful), but I’ve been unable to find a solution to my problem so far. I’m currently using WordPress 4.3 with BuddyPress 2.3.2.1 installed on my server. I have Extended Profiles enabled, and am using the plugin BuddyPress xProfiles ACL to manage custom extended profile groups assigned by user role.

    I have two roles that I am working with primarily – ‘students’ and ‘institutions’. Each of these roles have their own unique group of profile fields, some of which have the same name (e.g., each role has an ‘Address’ extended profile field). Within the bp_members loop, I am usually able to obtain a given user’s extended profile data by using the following function:

    $value = xprofile_get_field_data($field, $user_id);

    where $field is the name of the field I want to retrieve a value from in all lowercase letters (e.g., ‘Address’ would be ‘address’). I have run into an issue when trying to get field data from a profile field that has the same name for two separate user role groups. Using the same field name for both user roles will only return results for one of the roles (the role where that profile field was first created). I’m assuming the extended profile field for one of the user roles is being stored in the database with a slightly modified name, but I am unsure of how to retrieve this name.

    Is there a way to request all xprofile field names for a given group of users (or even an individual user)? If I can obtain a list of the xprofile field names – or more specifically, a list of strings I could pass to the xprofile_get_field_data function – I should be able to get all the data I am looking for.

    If you could please help me solve this problem, it would be greatly appreciated.

    Thanks a lot,
    Cam

Viewing 2 replies - 1 through 2 (of 2 total)
  • @shanebp

    Moderator

    I have run into an issue when trying to get field data from a profile field that has the same name for two separate user role groups.

    The simplest solution is to pass the field id rather than the field name.
    $value = xprofile_get_field_data($field_id, $user_id);
    You can get the field id by looking at the url in wp-admin when you edit that field, or just rolling over the edit button.

    @cplouffe

    Participant

    Great. This seems to work, but I will have to rejig the functions I’m currently working with – I was using the field name to create an HTML5 data attribute which I used to dynamically filter results client-side (e.g., before ‘province’ could be used to filter both user roles).

    I can probably just set up an object to do a lookup of the proper name after the fact.

    Thanks a lot!
    Cam

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get xprofile field names for different member roles’ is closed to new replies.
Skip to toolbar