Support » Plugin: BadgeOS » BadgeOS Custom Function : Achievement Number of a User

Viewing 1 replies (of 1 total)
  • Thread Starter X-Raym

    (@x-raym)

    Just succeed, modifing the code you give me for the “display all achivement of a user” (wich is very powerful 🙂

    here is my code :

    // Custom BadgeOS User Achievement Count
    function custom_badgeos_user_achievements_count( $args = array() ) {
      // Parse our arguments
    	$args = wp_parse_args(
    		$args,
    		array(
    			'user' => get_current_user_id(),
    			'type' => '',
    		)
    	);
    
    	// Grab the user's current achievements, without duplicates
    	$achievements = array_unique( badgeos_get_user_earned_achievement_ids( $args['user'], $args['type'] ) );
    
    	// Setup a counter
    	$count_total = 0;
    
    	// Loop through the achievements
    	if ( ! empty( $achievements ) ) {
    		foreach( $achievements as $achievement_id ) {
    			$count_total++;
    		}
        }
    
       return $count_total;
    
    }
    <?php echo custom_badgeos_user_achievements_count ( array( 'user' => $user->ID, 'type' => 'badges' ) );?>

    I will probably make a Gist for this 😛

Viewing 1 replies (of 1 total)
  • The topic ‘BadgeOS Custom Function : Achievement Number of a User’ is closed to new replies.