Skip to:
Content
Pages
Categories
Search
Top
Bottom

Duplicate profile field names


  • Henry
    Member

    @henrywright-1

    I have set up a profile group and called it “Work” and within it I have created a field called “Email”. I am displaying the field value in my theme like so

    echo bp_get_profile_field_data( 'field=Email' )

    If I now set up a new profile group called “Home” and have a field in it called “Email”, how can I display the value in my theme without getting a conflict?

    Am I forced to name the fields different under each profile group?

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

  • danbp
    Participant

    @danbp

    Hi @henrywright-1,

    i guess you can also filter by group profile ID

    <?php if ( bp_has_profile('profile_group_id=2') ) : 
    echo bp_get_profile_field_data( 'field=Email' )
    endif;
    
    if ( bp_has_profile('profile_group_id=45') ) : 
    echo bp_get_profile_field_data( 'field=Email' )
    endif;
    ?>

    https://codex.buddypress.org/developer/developer-docs/loops-reference/the-profile-fields-loop-bp_has_profile/


    Henry
    Member

    @henrywright-1

    @danbp

    I may be wrong but echo bp_get_profile_field_data( 'field=Email' ) won’t necessarily echo the “Email” field in profile group 2. All if ( bp_has_profile('profile_group_id=2') ) does is check if profile group 2 exists.


    danbp
    Participant

    @danbp

    You maybe right, and i’m unsure too. The best way to know, is to give a try. But do you absolutely need to ask twice for the user email ?
    Or you could simply name the email fields differently.
    Private mail
    Work mail

    I guess in some respects the easiest option might have been to label:
    ‘Work email’
    ‘Home email’
    and perhaps in a profile or list /address one would sort of automatically label in that fashion.

    There is also bp_get_profile_group_name() or similar name so you could do work == bp_profile_get_group_name() but that would only make sense in a loop really.


    Henry
    Member

    @henrywright-1

    Thanks for the feedback guys. I have quite a few field names that could easily be duplicates. My current workaround is exactly what you’ve suggested (naming them all differently “Work email” “Home email” and so on). I was hoping there was some easy approach I was overlooking

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Duplicate profile field names’ is closed to new replies.
Skip to toolbar