您好我正在尝试查询上个月产品销售最多的用户。 有没有办法去取得上个月产品销量最多的前50名作者。 目前我只是通过wp用户查询来查询50个供应商,但无法通过销售报告订购。
$current_page = $_GET['page-num'] ? (int) $_GET['page-num'] : 1;
$users_per_page = 50; // RAISE THIS AFTER TESTING ;)
$args = array(
'role' => 'Vendor',
'number' => $users_per_page, // How many per page
'paged' => $current_page, // What page to get, starting from 1.
'orderby' => 'login',
'order' => 'ASC',
);
$users = new WP_User_Query( $args );
如果有人对此有任何想法请帮忙。谢谢你提前做好准备。
更多修改:
现在我已经制作了这个代码来获取前50名供应商,但不是根据上个月的销售情况。
global $wpdb;
$atts = array(
'post_type' => 'product',
'fields' => 'ids',
'posts_per_page' => -1
);
$posts = new WP_Query( $atts );
$posts = implode( ',', $posts->posts );
$users = $wpdb->get_results( "SELECT post_author,SUM(meta.meta_value) AS total_sales FROM $wpdb->posts LEFT JOIN wp_postmeta AS meta ON (wp_posts.ID = meta.post_id) WHERE ID IN ($posts) AND meta.meta_key = 'total_sales' GROUP BY post_author ORDER BY total_sales DESC LIMIT 50" );