This is how things work
I use Wordpress category tables and have 2 main categories. The first one is called "location
" and the other one "subject
". Both categories have sub categories of their own.
In my example we have "location
" category 17 and "subject
" category 3.
This is what I want to do
I want to select ONLY the data where BOTH my categories 17 AND 3 are presented.
This code works so far
SELECT term_id, post_title, post_name, ID, object_id, post_status
FROM wp_posts AS wpost
INNER JOIN wp_term_relationships
ON wpost.ID = wp_term_relationships.object_id
INNER JOIN wp_term_taxonomy
ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy = 'category'
WHERE wp_term_taxonomy.term_id IN (17, 3)
AND post_status = 'publish'
The problem
Both categories 17 and 3 exists in the same column. The code above lists the IDs twice if the posts apears in both categories.
Is there a way to count the IDs that are equal in the result? If ID exists twice, select the post from that ID.