public function get_posts_total() { $totals = array(); global $wpdb, $blog_id; $my_data = $wpdb->get_results($wpdb->prepare("SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d GROUP BY post_id ORDER BY count DESC ", $blog_id)); if (!empty($my_data)) { foreach ($my_data as $row) { $totals[] = new Sharing_Post_Total($row->id, $row->total); } } usort($totals, array('Sharing_Post_Total', 'cmp')); return $totals; }