如何将这个在wordpress下工作的查询转换为在php中的另一个站点上使用
global $wpdb;
$ID_CATEGORY = 10;
$query = $wpdb->prepare("SELECT {$wpdb->prefix}users.ID, {$wpdb->prefix}users.display_name as user_nicename, COUNT(*) as count
FROM {$wpdb->prefix}posts, {$wpdb->prefix}users, {$wpdb->prefix}term_relationships
WHERE {$wpdb->prefix}posts.post_type=\'post\'
AND {$wpdb->prefix}posts.post_status=\'publish\'
AND {$wpdb->prefix}posts.post_author = {$wpdb->prefix}users.ID
AND {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id
AND {$wpdb->prefix}term_relationships.term_taxonomy_id = %d
GROUP BY post_author ORDER BY count DESC LIMIT 5 ;", $ID_CATEGORY);
$results = $wpdb->get_results($query, OBJECT);
SO网友:flexi2202
我刚找到答案
"SELECT post_title ,post_date, display_name ,wp_users.ID, wp_users.display_name as user_nicename, COUNT(*) as count
FROM wp_posts, wp_users, wp_term_relationships
WHERE wp_posts.post_type=\'post\'
AND wp_posts.post_status=\'publish\'
AND wp_posts.post_author = wp_users.ID
AND wp_posts.ID = wp_term_relationships.object_id
AND wp_term_relationships.term_taxonomy_id = \'10\'
GROUP BY post_author ORDER BY count DESC LIMIT 5 ;"