views:

45

answers:

3

Is it possible to fetch posts matching categorie x "AND" tag y?

Read the docs, it seems you can do:

query_posts('tag=bread,baking');

or

query_posts('cat=2,6,17,38');

... is it possible to use both cat and tag simultaneously?

+2  A: 

I am not a wordpress expert, but what I see from looking up that function, is that you should be able to use this notation in order to query against both at the same time.

query_posts('tag=bread,baking&cat=2,6,17,38');

HTH, Jc

JC
That's correct! :)
TiuTalk
+1  A: 

This is taken from another question that I had answered previously and it was tested and worked properly, so here we go. You can manually query your database using the following:

SELECT *  
FROM wp_term_taxonomy AS cat_term_taxonomy 
INNER JOIN wp_terms AS cat_terms ON cat_term_taxonomy.term_id = cat_terms.term_id 
INNER JOIN wp_term_relationships AS cat_term_relationships ON cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id 
INNER JOIN wp_posts AS cat_posts ON cat_term_relationships.object_id = cat_posts.ID 
WHERE cat_posts.post_status = 'publish' AND cat_posts.post_type = 'post' AND cat_terms.term_id = '13,26,45,89,117'

All that you would do is that you would provide the termID for each of the tags/categories that you want to find.

I'm not sure if it would work or not, but technically tags and categories are within the same table. So, I would think that if you provide the tagID within the cat= parameter it might work, I don't have a chance to test it currently, but definitely worth a try.

David
A: 

Yes, you can. I recently had to show all future posts on a page of my wordpress log and I just used:

query_posts($query_string . '&post_status=future,publish');

which worked flawlessly.

Anax