Re: How do I use Buddypress xprofile fields inside bbPress?
Sure thing @modemlooper. The code below will look for all the custom fields that a user has filled in, compare them to what should be visible for the currently logged-in user and then loop and display the forum reply user’s data. Instead of simply looping the default titles and data of the xprofile fields, I do a custom switch/case so that I can format each field individually for more control.
`
$user_strAllFields = get_user_meta( bbp_get_reply_author_id(), bp_get_user_meta_key( ‘bp_xprofile_visibility_levels’ ), true );
// get all the completed user fields for this poster
if( $user_strAllFields != null ) :
$user_arrAllFields = array_keys( $user_strAllFields );
else :
$user_arrAllFields = array();
endif;
// get all the fields that should not be displayed for this poster
$user_arrHiddenFields = bp_xprofile_get_hidden_fields_for_user( bbp_get_reply_author_id() );
// loop through all the poster filled-in fields
foreach( $user_arrAllFields as $field ) :
// exclude the ones that should not be displayed
if( !in_array( $field, $user_arrHiddenFields ) ) :
// turn the ID of a field into its object
$obj_field = xprofile_get_field( $field, bbp_get_reply_author_id() ) ;
// depending on the field name, customize the display
switch( $obj_field->name ) :
case ‘Location’ :
$user_location = xprofile_get_field_data( ‘Location’, bbp_get_reply_author_id() ) ;
if (strlen($user_location) > 0 ) :
echo ‘
Location: ‘ . $user_location . ‘
‘;
endif;
break;
endswitch;
endif; // !in_array( $field, $user_arrHiddenFields ) )
endforeach; //( $user_arrAllFields as $field )
`