我想计算一个类别和月/年的已发布帖子,但我不能......
我可以为一个类别(没有设置月/年):
SELECT wp_term_taxonomy.count
FROM wp_terms, wp_term_taxonomy
WHERE wp_terms.term_id=wp_term_taxonomy.term_id
AND wp_term_taxonomy.term_id=7
但不是月/年:
SELECT count
FROM wp_term_taxonomy, wp_posts, wp_term_relationships
WHERE wp_posts.ID = wp_term_relationships.object_id
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
AND wp_term_taxonomy.term_id = '7'
AND wp_posts.post_type = 'post'
AND wp_posts.post_status = 'publish'
AND wp_posts.post_date LIKE '2011-06-%'
感谢您的帮助:)
答案 0 :(得分:1)
SELECT COUNT(*)
FROM wp_term_taxonomy, wp_posts, wp_term_relationships
WHERE wp_posts.ID = wp_term_relationships.object_id
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
AND wp_term_taxonomy.term_id = '7'
AND wp_posts.post_type = 'post'
AND wp_posts.post_status = 'publish'
AND YEAR(wp_posts.post_date) =2011
AND MONTH(wp_posts.post_date) =6
或者用
之间替换最后两行AND wp_posts.post_date BETWEEN '2011-06-01' AND '2011-06-30'