禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

wordpress如何获取每个分类下所有文章的收入统计

禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。
基于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 个评论

 
联系
目前暂停一切业务,客服消息可能不会及时回复,谢谢理解。
在线咨询
    在线咨询
    禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。