Function for returning profile data
-
Hello,
I know this is a common topic regarding using xprofile_get_field_data. However, I’ve spent way too many hour to get this to work. My goal is to have a function in my childtheme’s function.php that returns a users profile data. I’ve made a dummy function below that should bring out the profile data from the field Yrkesroll, from user 1 and present it in comma format. When the function is called, nothing happens..
function bp_user_yrkes(){ $field = 'Yrkesroll'; // The ID of the user. $user_id = 1; // How should array data be returned? 'comma' if you want a // comma-separated string; 'array' if you want an array. $multi_format = 'comma'; // NOTICE! Understand what this does before running. $result = xprofile_get_field_data($field, $user_id, $multi_format); echo $result; } bp_user_yrkes();
I also made another function:
add_action( 'bp_ready', 'hisgen_check' ); function hisgen_check() { echo xprofile_get_field_data( 'Yrkesroll', 1, 'comma' ); } hisgen_check();
This works perfectly and echo the profile data, but as fast as I try to make that this function is returning the data instead of echo, this doesn’t work. It has something to do with “add_action( ‘bp_ready’, ‘hisgen_check’ );” I guess.
Some guidelines here would be perfect. Thanks in advance!
- You must be logged in to reply to this topic.