EDIT
这是正确问题的答案。
$categories = $wpdb->get_results(
$wpdb->prepare(
"SELECT c.categoryid as id, c.name, c.public, COUNT(jc.categoryid) as submissions
FROM ".$wpdb->prefix."judge_category c LEFT JOIN ". $wpdb->prefix. "judge_submission_category jc
ON jc.categoryid = c.categoryid %s GROUP BY c.categoryid %s", $_where, $_order
)
);
PREVIOUS ANSWER BASED ON THE ORIGINAL QUESTION
将查询更改为以下内容
$judges = $wpdb->get_results(
$wpdb->prepare(
"SELECT u.ID, u.user_login, u.display_name, u.user_nicename, u.user_status, COUNT(c.categoryid) as categories
FROM ".$wpdb->prefix."users u LEFT JOIN ". $wpdb->prefix."judge_judge_category c
ON c.ID = u.ID WHERE (SELECT umeta_id FROM ". $wpdb->prefix. "usermeta
WHERE user_id = u.ID AND meta_key = \'wp_capabilities\' AND
meta_value LIKE \'%%judge%%\') > 0 %s GROUP BY u.ID %s",
$_where, $_order)
);