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.
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
The topic ‘ [Resolved] Struggling with serialized data with BuddyPress Xprofile Custom Field Types’ is closed to new replies.