BuddyDev

Search

[Resolved] Struggling with serialized data with BuddyPress Xprofile Custom Field Types

  • Participant
    Level: Initiated
    Posts: 2
    Meet Mingle Swing on #34426

    Hi,
    I am working from a previous developer’s code, am fairly new to Buddypress/boss/dev and know enough PHP to break things.

    His work does not call in any other serialized fields so after many links and other sources, I have come to 3 or 4 different versions for this code and only two worked … sort of.

    I am trying to echo the gender field, which is a checkbox. I assume I’m not understanding how to unserialize the data. Though there might be other issues as well, it does pull correctly for the profile. (small victories…)

    ////////// This version displays an “F” for a female but for a male, I get an “h” //////////

    
    $gender = xprofile_get_field_data('706', bp_get_member_user_id())[0];
    if ($gender) { echo "Gender: " . $gender . "<br />"; }

    ////////// This version displays his_Male or her_Female //////////

    $gender = xprofile_get_field_data('706', bp_get_member_user_id(), 'comma');
    if ($gender) { echo "Gender: " . $gender . "<br />"; }

    Thanks so much for your time, it’s greatly appreciated. r.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #34427

    Hi,
    Thank you for the question.

    Your use of the code

    
    $gender = xprofile_get_field_data('706', bp_get_member_user_id(), 'comma');
    

    Is the correct way to use it.

    The values are correct as they are what BuddyBoss stores.
    Your only way to get male/female(if that is what you are looking for) is to either split the value and show the second part or use string matching.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 2
    Meet Mingle Swing on #34433

    Oh, ok, thank you so much.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #34434

    You are welcome.

The topic ‘ [Resolved] Struggling with serialized data with BuddyPress Xprofile Custom Field Types’ is closed to new replies.

This topic is: resolved