BuddyDev

Search

Adding Xprofile fields to Recent Visitors directory?

  • Participant
    Level: Guru
    Posts: 995
    calu on #31144

    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

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #31148

    Hello Carsten,

    Thank you for posting. Are you looking for a way to populate extra data in Member’s directory > Recent Visitor specific tab only?. Plese let me know.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 995
    calu on #31149

    Hi Ravi, thanks for your reply, yes that is my goal, exactly the way the code in the link above, is working in
    Members Directory

    Regards
    Carsten

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #31150

    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
    Ravi

  • Participant
    Level: Guru
    Posts: 995
    calu on #31152

    Hi Ravi, thanks for bringing up a solution so quickly.

    Does this code cover both members directory and recent visitors directory, so I can delete the existing code I use for adding extra data the Members directory?

    Regards
    Carsten

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #31153

    Hello Carsten,

    No, It is only for Recent Visitors tab only if you want to use it globally for all tabs just remove the following code.

    
    if ( ! function_exists( 'visitors_is_visitor_scope' ) || ! visitors_is_visitor_scope() ) {
    		return;
    	}
    
    

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 995
    calu on #31161

    Hi Ravi, hmmm, it is not rendered out, should I wrap in the content like this?

    <?php echo $bphelp_my_profile_field_1 ?>:&nbsp;<strong><?php echo bp_member_profile_data( 'field='.$bphelp_my_profile_field_1 ); ?>

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #31163

    Hello 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.

You must be logged in to reply to this topic.

This topic is: not resolved