Media count


#1

I am trying to display the total number of

a) videos b) audio c) photos d) media

Anyone know how to get the total count for each of these?


#2

Hi,

As of now, each user's counts are stored in a user meta:

bp_get_user_meta($user_id, 'bp_media_count', true);  

This returns an array:

$bp_media_count = array(  
    0 => array('images' => 0, 'videos' => 0, 'audio' => 0, 'albums' => 0),  
    2 => array('images' => 0, 'videos' => 0, 'audio' => 0, 'albums' => 0),  
    4 => array('images' => 0, 'videos' => 0, 'audio' => 0, 'albums' => 0),  
    6 => array('images' => 0, 'videos' => 0, 'audio' => 0, 'albums' => 0),  
);  

Where 0 is public, 2 is for logged in users, 4 is friends only and 6 is private. These are privacy levels.

So, the only way now to get the total count is to loop through all the users and then total, all the counts. However, we'll try and factor this in so that one may get a total count stored in the options table.

Regards.


#3

Hi Saurabh

Thanks for the info. I don't need a site wide count, I just need to display the total number of videos, photos and audio each user has uploaded.


#4

I've come up with this

function bp_video_total_count( $user_id = 0 ) { global $bp_media_count, $bp_media; $bp_video_count = bp_get_user_meta( $user_id, 'bp_media_count', true );

        echo $bp_video_count[0]['image'];  

}

Hope this is the right way to do it?


#5

Oops that copy/paste didn't work very well. Think you can still see the function OK.


#6

Hi,

Actually, it'd be this:

function bp_video_total_count( $user_id = false ) {  
    if ( !$user_id ){  
        $user_id = bp_displayed_user_id(); //if this is on a profile  
    }  

    $video_count = 0;  

    $bp_media_count = bp_get_user_meta($user_id, 'bp_media_count', true);  

    // this will just get the total public video count  
    $video_count = $bp_media_count[0]['videos'];  

    echo $video_count;  
}  

#7

I did actually have

$video_count = $bp_media_count[0]['videos']

I realise in my post I had written ['image']

Thanks for helping me to get it working, much appreciated!


#8

#9