Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Last active August 30, 2020 17:36
Show Gist options
  • Save MrVibe/be8ab01de311db3f6df81a529665db37 to your computer and use it in GitHub Desktop.
Save MrVibe/be8ab01de311db3f6df81a529665db37 to your computer and use it in GitHub Desktop.
Get top 15 quiz scorers
add_shortcode('wplms_quiz_top_scorers',function($atts,$content = null){
extract(shortcode_atts(array(
'count' => 5,
)));
global $wpdb;
$results = $wpdb->get_results("select meta_key as user_id,sum(meta_value) as total from $wpdb->postmeta as m left join $wpdb->posts as p on p.ID = m.post_id where p.post_type = 'quiz' and m.meta_key REGEXP '^[0-9]+$' group by user_id order by total DESC limit 0,$count");
$html='';
if(!empty($results)){
$html.='<div class="quiz_top_scores">';
foreach($results as $result){
$html.='<div class="quiz_top_scorer">';
$html.='<div class="student_avatar">'.bp_core_fetch_avatar(array('item_id'=>$result->user_id,'type'=>'thumb')).'</div>';
$html .='<div class="student_details">
'.bp_core_get_user_displayname($result->user_id).'
<span>'.$result->total.'</span>
</div>';
$html .='</div>';
}
$html .='</div>';
}
return $html;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment