Join the myCred Membership Club today & Save 30% on all 3-Year plans! " Click Here To Get Started "

Total Group Points in buddypress

front page Forums How-to Questions Total Group Points in buddypress

This topic contains 2 replies, has 1 voice, and was last updated by Avatar CarlenY 1 month, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #53245
    Avatar
    CarlenY

    I am not great with queries and am trying to set up a custom query to display the following on the group page (I am creating a custom bp group template page):

    Total points that a buddypress group has.
    Total amount of badges a buddypress group has.

    Any help or direction would be greatly appreciated.

    #53754
    Avatar
    CarlenY

    I found a solution for my unique use case. I am using total points as it is easy enough to calculate what badge level a user has too. Probably could do this several other ways and look up badges themselves.

    function group_members_counter() {
        $group_id_1 = bp_get_current_group_id();
    	$args = array(
    		'group_id' 		=> $group_id_1,  // bp_get_group_id(), or pass in a group id
    		'exclude_admins_mods' 	=> false
    	);
    
    	$group_members_result = groups_get_group_members( $args );
    	$group_members_ids = array();
    
    	foreach(  $group_members_result['members'] as $member ) {
    		$group_members_ids[] = $member->ID;
    	}
    
    	echo 'group member ids: ' . implode(", ", $group_members_ids);
    
    	if ( ! empty ( $group_members_ids ) ) {
    
    		$args = array(
    			'include' 		=> $group_members_ids,
    			'meta_key'		=> 'action_one_total',
    			'meta_value'		=> array( '0', '100' ),
    			'compare' => 'BETWEEN',
    			'populate_extras' 	=> false
    		);
    
    		$members = new BP_User_Query( $args );
    		
    		echo '<br>Total Custom Points: ' . $members->total_users;
    
    	} else {
    		echo 'There are no group members.';
    
    	}
    
    }	
    echo group_members_counter(); 
    #53759
    Avatar
    CarlenY

    Nevermind… still learning:

    Way easier to do this:

    <?php 
    	function group_members_counter() {
        $group_id_2 = bp_get_current_group_id();
    	$args = array(
    		'group_id' 		=> $group_id_2,  // bp_get_group_id(), or pass in a group id
    		'exclude_admins_mods' 	=> false
    	);
    
    	$group_members_result = groups_get_group_members( $args );
    	$group_members_ids = array();
    
    	foreach(  $group_members_result['members'] as $member ) {
    		$group_members_ids[] = $member->ID;
    	}
    
    	echo 'group member ids: ' . implode(", ", $group_members_ids);
    	
    	if ( ! empty ( $group_members_ids ) ) {
    		$args = array(
    			'include' 		=> $group_members_ids,
    			'meta_key'		=> 'mycred_badge6750',
    			'meta_value'	=> 3,
    			'compare' => '=',
    			'type' => 'NUMERIC',
    			'populate_extras' => false
    		);
    		$members = new BP_User_Query( $args );
    		
    		$total1 = $members->total_users;
    		echo '<br>Bronze Medals: ' . $total1;
    
    	} else {
    		echo 'There are no group members.';
    
    	}
    
    }		
    		?>
    <?php echo group_members_counter(); ?>	
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

11