基于erphpdown售卖资源,统计每个分类出售文章销量统计(基本是基于子分类的)。
$sql = "SELECT t.term_id AS category_id, t.name AS category_name, COUNT(a.ice_id) AS total_sales, SUM(a.ice_price) AS total_prices FROM $wpdb->term_taxonomy tt JOIN $wpdb->terms t ON tt.term_id = t.term_id JOIN $wpdb->term_relationships tr ON tt.term_taxonomy_id = tr.term_taxonomy_id JOIN $wpdb->posts p ON tr.object_id = p.ID LEFT JOIN $wpdb->icealipay a ON p.ID = a.ice_post WHERE tt.taxonomy = 'category' AND p.post_type = 'post' AND p.post_status = 'publish' GROUP BY t.term_id, t.name ORDER BY total_sales DESC"; $list = $wpdb->get_results($sql); if($list) { foreach($list as $value){ if($value->total_sales > 0){ echo '<tr> <td><a href="'.get_category_link($value->category_id).'" target="_blank">' . $value->category_name . '</a></td> <td>'.$value->total_sales.'</td> <td>'.$value->total_prices.'</td> </tr>'; } } }
0 个评论