/**
* Display currently earned badges for author.
* @param integer $count How many posts to display per page
* @param integer $author_id ID of the author to display. Defaults to ID 1
* @return mixed echo'd badge loop.
*/
function custom_badgeos_user_achievements( $count = 1, $author_id = 1 ) {
//Use the current user if no specific user specified.
if ( 1 === absint( $author_id ) ) {
global $post;
$author_id = $post->post_author;
}
//Re-fetch our data if the transient has expired.
if ( false === ( $badges = get_transient( 'custom_badgeos_user_achievements' ) ) ) {
//Grab the user's current list of achievements, by ID
$ids = badgeos_get_user_earned_achievement_ids( $author_id );
$types = array();
foreach( $ids as $id ) :
//shuffle the badge type into its own array.
$types[] = get_post_type( $id );
endforeach;
//Assign our arguments based on passed in parameters and unique badge types and only earned badges by ID.
$args = array(
'posts_per_page' => $count,
'post_type' => array_unique($types),
'post__in' => $ids
);
$badges = new WP_Query( $args );
//store our resulting WP_Query object in a transient for one hour.
set_transient( 'custom_badgeos_user_achievements', $badges, 60*60 );
}
//Loop through our badges as we would any other post listing, display the parts we want.
if( $badges->have_posts() ) : while( $badges->have_posts() ) : $badges->the_post(); ?>
<?php echo badgeos_get_achievement_post_thumbnail(); ?>
<span class="badgeos-title-wrap"><?php the_title(); ?></span>
<?php endwhile; wp_reset_postdata(); endif;
}