我需要一些帮助,查询应该根据他们的 wp-postratings 分数返回帖子 (http://wordpress.org/extend/plugins/wp-postratings/)。
用户选择最低评分(0 到 5 星)和最高评分(0 到 5 星),查询应返回匹配的帖子。我让它在两个值的用户输入都高于 0 的情况下工作,但我似乎无法理解 0 值。由于 0 表示未评级的帖子 - 因此也有一次没有评级元数据 - 我不仅需要选择评级不超过指定最大值的帖子,还需要选择每个没有评级元数据的帖子。
我怎样才能做到这一点??任何帮助将不胜感激!
这是我当前的查询:
SELECT DISTINCT p.*, (t1.meta_value+0.00) AS ratings_average, (t2.meta_value+0.00) AS ratings_users, (t3.meta_value+0.00) AS ratings_score
FROM wp_posts p
INNER JOIN wp_term_relationships tr ON (p.ID = tr.object_id)
INNER JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN wp_terms t ON t.term_id = tt.term_id
LEFT JOIN wp_postmeta AS t1 ON t1.post_id = p.ID
LEFT JOIN wp_postmeta AS t2 ON t1.post_id = t2.post_id
LEFT JOIN wp_postmeta AS t3 ON t3.post_id = p.ID
WHERE t1.meta_key = 'ratings_average'
AND t2.meta_key = 'ratings_users'
AND t3.meta_key = 'ratings_score'
AND p.post_date < NOW()
AND p.post_status = 'publish'
AND (tt.taxonomy = 'post_tag' AND tt.term_id = t.term_id AND t.slug = 'liverpool')
AND ( (t1.meta_value+0.00) IS NULL OR (t1.meta_value+0.00) <= $max_stars )
ORDER BY p.post_date DESC
LIMIT 20