我正在运行一个 Wordpress 站点,并且正在制作一个小部件,它可以为我提供过去 8 天内阅读次数最多的所有帖子。
当我运行这个 SQL 字符串时,我得到了所有带有类别的帖子,但是当帖子不在一个类别中时,我不明白。
如何获取属于某个类别的所有帖子,以及所有不在某个类别中的帖子?
我的 sql 字符串
$sql ="SELECT wp_posts.post_date, wp_posts.post_title, wp_posts.post_name, wp_posts.post_content, wp_terms.name, wp_terms.slug, wp_postmeta.meta_value FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
INNER JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id)
INNER JOIN wp_postmeta ON (wp_postmeta.post_id = wp_posts.ID)
WHERE (wp_term_taxonomy.taxonomy = 'category'
AND wp_postmeta.meta_key = 'readCount'
AND wp_posts.post_type = 'post'
AND DATE(wp_posts.post_date) >= '$eight_days_ago'
AND wp_posts.post_status = 'publish')
GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value DESC
LIMIT 5";