我在这个问题上做错了什么?主要问题是var_dump
返回null。该查询在phpMyAdmin中运行良好。
global $wpdb;
$users = $wpdb->get_results(
$wpdb->prepare(
"SELECT
u.ID AS id,
u.user_login AS name,
AVG(b.star) AS rating,
COUNT(b.star) AS reviews,
m.meta_value AS roles
FROM
wp_users AS u
LEFT JOIN
wp_usermeta AS m ON u.ID = m.user_id
LEFT JOIN
wp_bp_activity AS b ON u.ID = b.usercheck
WHERE
(m.meta_key = \'wp_capabilities\' AND m.meta_value LIKE \'%subscriber%\')
AND
(b.is_activated is null or b.is_activated = 1)
GROUP BY u.ID
ORDER BY reviews DESC
LIMIT %d", $limit
)
);
return var_dump($users);
最合适的回答,由SO网友:birgire 整理而成
小心\'%subscriber%\'
零件,内部wpdb::prepare()
方法
使用\'%%subscriber%%\'
相反
否则$limit
将匹配%s
零件和%d
零件将不匹配。