我遇到了一种情况,我必须在检查和取消检查条款时显示帖子。
已分配条款的帖子。我有术语“区域”和“美食”,现在我必须选择具有区域“XYZ”和美食“ABC”的帖子。
我尝试过的查询:-
SELECT p.ID, p.post_title
FROM wp_posts p
LEFT JOIN `wp_term_relationships` t
ON p.ID = t.object_id
LEFT JOIN `wp_term_taxonomy` tt
ON t.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.term_id IN (".$area.")
OR tt.term_id IN (".$cuis.")
GROUP BY t.object_id
HAVING COUNT( t.term_taxonomy_id ) = 2
LIMIT 0,7
wp_term_taxonomy 的结构如下所示:-
问题是单个表和单个列,并在值之间应用 AND 运算符。
wp_term_relationship
object_id | wp_term_taxonomy_id | term_order
==============================================
134 | 36 | 0
______________________________________________
135 | 36 | 0
wp_posts
ID | post_title |
==================================
1 | Hello world! |
__________________________________
2 | Test |
wp_term_taxnomy
term_taxonomy_id term_id taxonomy description parent count
=============================================================================
1 1 category ------ 0 2