BuddyBoss Home – Web Support Forums Plugins BuddyBoss Media Display photos count in member header

Viewing 6 posts - 1 through 6 (of 6 total)
  • Question

    #44735
    @surfbuddy

    Hey guys, how can I display the photos count next to followers/following in member header?

    Answers

    #44912

    Alyssa
    Participant
    @alyssa-buddyboss

    @surfied unfortunately we do not have a function for this but this might work; add this function to functions.php:

    function buddyboss_member_photo_count(){
    global $wpdb, $bp;
    
    		if ( ! isset( $bp->displayed_user->id ) && !  is_admin() )
    		{
    			return;
    		}
    
    		$photos_user_id      = isset( $bp->displayed_user->id ) ? $bp->displayed_user->id : '';
    		
    		$new_sql = "SELECT COUNT(id) FROM {$wpdb->prefix}buddyboss_media WHERE media_author = %d";
    		
    		$sql = $wpdb->prepare( $new_sql, $photos_user_id );
    
    		$photos_cnt = $wpdb->get_var( $sql );
    
    		echo $photos_cnt;
    }

    Then use that function wherever you want to display the photo count. They styling is left up to you 😉

    #44931
    @surfbuddy

    Thanks @tjchester! I added that to my child themes function.php and added the following to line 87 of members/single/member-header.php, but the count is incorrect and showing as zero.

                        	<a href="<?php bp_displayed_user_link(); ?>photos">
    			            <span>
                                <p><?php echo (int) $photos_cnt["buddyboss_media"]; ?></p>
                                <p><?php _e("Photos","boss"); ?></p>
                            </span></a>
    
    #44950

    Alyssa
    Participant
    @alyssa-buddyboss

    @surfied Instead of this:
    echo (int) $photos_cnt["buddyboss_media"];
    simply this function, no need to echo:
    buddyboss_member_photo_count();

    #45050
    @surfbuddy

    Works perfectly now! Thanks @tjchester!

    #45115

    Alyssa
    Participant
    @alyssa-buddyboss

    🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • The question ‘Display photos count in member header’ is closed to new replies.