我已經陷入了一種情況,在那裏我必須顯示帖子檢查和取消條款。從term_taxnomy表中選擇使用AND
已分配條款的帖子。我有'區'和'美食'的條款,現在我必須選擇區域'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的結構如下所示: -
的問題是單個表和單列,並將與運算值之間。
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
你可以給你在'select'語句中使用以下列的示例記錄嗎? –
我編輯了這個問題。請檢查。 –