I need to get the last posts' ID and the post_tile within categories 1 and 2, and exclude those within category 3. It must be SQL, because if I use WP_Query it retrieves too much info and I only need the ID and post_title.
The following query works fine getting posts from the 2 categories, but if I try excluding the third one, it doesn't work:
select distinct p.ID, p.post_title
from wp_posts p,
wp_terms t, wp_term_taxonomy tt, wp_term_relationships tr,
wp_terms t2, wp_term_taxonomy tt2, wp_term_relationships tr2
where p.id = tr.object_id
and t.term_id = tt.term_id
and tr.term_taxonomy_id = tt.term_taxonomy_id
and p.id = tr2.object_id
and t2.term_id = tt2.term_id
and tr2.term_taxonomy_id = tt2.term_taxonomy_id
and (tt.taxonomy = 'category' and tt.term_id = t.term_id and t.term_id = 15)
and (tt2.taxonomy = 'category' and tt2.term_id = t2.term_id and t2.term_id = 5)
ORDER BY p.ID DESC
LIMIT 0, 60
Any help?
Thanks in advance :)