Hi Brajesh, I want to add Xprofile fields to my Recent Visitors directory like my Members Directory using the the code from https://buddydev.com/snippets/ ‘Add Xprofile fields to the members directory’ .
Can I add something to this code, to have Xprofile fields to Recent Visitors Directory?
Regards, and thanks
Carsten
Hello Carsten,
Thank you for acknowledgement. Use the following code to print extra content in Recent Visitors tab
/** * Adding extra content to member's directory */ function buddydev_recent_visitors_extra_content() { if ( ! function_exists( 'visitors_is_visitor_scope' ) || ! visitors_is_visitor_scope() ) { return; } echo "put you content here"; } add_action( 'bp_directory_members_item', 'buddydev_recent_visitors_extra_content' );
Regards
RaviHello Carsten,
Try the following way to show specific field data. It will only show if data is not empty for the user.
/** * Adding extra content to member's directory */ function buddydev_recent_visitors_extra_content() { if ( ! bp_is_active( 'xprofile' ) ) { return; } // Show data from following fields. $fields = array( 2, 3 ); $user_id = bp_get_member_user_id(); foreach ( $fields as $field_id ) { $field = xprofile_get_field( $field_id, $user_id ); if ( ! empty( $field->data->value ) ) { echo $field->name . ': ' . $field->data->value . "</br>"; } } } add_action( 'bp_directory_members_item', 'buddydev_recent_visitors_extra_content' );
Please let me know if it works or not.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic.
This topic is: not resolved