Skip to:
Content
Pages
Categories
Search
Top
Bottom

Getting a list of users activity count

  • Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    I need an easy way to list each user with the count of each activity they have done on site. Does not have to be pretty I’m not using it to display onsite its for private use.

    So need a count of each comment, activity update, forum post, forum reply

    anyway to get this from DB?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Profile photo of PJ
    PJ
    Participant

    @pjnu

    I support some sort of way to get user metrics. I’m not sure if Google Analytics can provide this scope of information. It would have to come from BP’s core somehow or as I plugin I imagine.

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    @R-A-Y will know ;)

    I can output a single users activity but I need to get a list of each username with the total count of activity. This has nothing to do with analytics.

    Profile photo of dre1080
    dre1080
    Member

    @dre1080

    got this thanks to Boones Gorges..

    insert this in your bp-custom.php to get the total count of activity posts of a user:

    function get_activity_count_by_user( $user_id ) {

    $args = array(

    ‘per_page’ => 10000,

    ‘show_hidden’ => true,

    ‘user_id’ => $user_id

    );

    if ( bp_has_activities( $args ) ) {

    global $activities_template;

    $count = $activities_template->total_activity_count;

    } else {

    $count = 0;

    }

    return $count;

    }

    then use this template tag in your theme <?php echo get_activity_count_by_user( $user_id ) ?>

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Yeah I can do that what I need is a list of every user this is not for a template or theme out put I just need to get the total count for each user.

    Like:

    user1 12

    user2 426

    user3 45

    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    I’d store it in a usermeta item. Write a function that gets called every time an activity item

    is recorded, and increment the activity count by one. You’ll also need to write a script that loops through all your members and figures out an initial value for the user activity count. Then just use get_usermeta to get the count when needed.

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Dont need to store anything. I figured it would be simple to get. I only need this info once.

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Dont need to store anything. I figured it would be simple to get. I only need this info once.

    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    Ah, if you only need it once, then it’s easier. Build a list of all members

    $query = "SELECT * FROM {$wpdb->users} WHERE spam=0";
    $members = $wpdb->get_results( $query, ARRAY_A );

    Then loop through $members and do the operation that dre1080 mentions above:

    foreach ( $members as $member ) {
    $user_id = $member['ID'];

    $args = array(
    'per_page' => 10000,
    'show_hidden' => true,
    'user_id' => $user_id
    );

    if ( bp_has_activities( $args ) ) {
    global $activities_template;
    $count = $activities_template->total_activity_count;
    } else {
    $count = 0;
    }

    echo $user_id . " " . $count . "<br />";

    }

    I haven’t tested this but it or something very similar to it should print a list on the screen of user ids along side their activity counts.

    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    Ah, if you only need it once, then it’s easier. Build a list of all members

    $query = "SELECT * FROM {$wpdb->users} WHERE spam=0";
    $members = $wpdb->get_results( $query, ARRAY_A );

    Then loop through $members and do the operation that dre1080 mentions above:

    foreach ( $members as $member ) {
    $user_id = $member['ID'];

    $args = array(
    'per_page' => 10000,
    'show_hidden' => true,
    'user_id' => $user_id
    );

    if ( bp_has_activities( $args ) ) {
    global $activities_template;
    $count = $activities_template->total_activity_count;
    } else {
    $count = 0;
    }

    echo $user_id . " " . $count . "<br />";

    }

    I haven’t tested this but it or something very similar to it should print a list on the screen of user ids along side their activity counts.

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    That code worked without WHERE spam=0 but it outputs the user ID number, anyway to get the username?

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    That code worked without WHERE spam=0 but it outputs the user ID number, anyway to get the username?

    Profile photo of Nm
    nm
    Participant

    @nahummadrid

    I’m trying to figure out what the difference is between the activity count that spits out using the old plugin Buddypress Member Profile Stats and using this code. This code shows a higher number than that of the plugin. Does one take into account reply comments or deleted updates. Anyone know this. trying to decide which one is more accurate.

    Profile photo of vcord
    vcord
    Participant

    @vcord

    hello, is there a way to get the total count for all the favourites a user has made on others posts and also get the total count for the favourites a user has recieved from all his activities. e.g:
    total favourites made:237.
    total favourites recieved from all posts:300.
    Am using Buddypress 1.8
    PLEASE I WILL BE APPRECIATE A QUICK RESPONSE.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Getting a list of users activity count’ is closed to new replies.
Skip to toolbar