Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hello friends I am new to wordpress.

I have used query like this query_posts('cat=1,2,3')

now If category 1 is parent of 2 and 3.

then query_posts('cat=1') and query_posts('cat=1,2,3') will get same posts or not? or how can I manage If I want to include posts form subcategories.

share|improve this question
1  
Title is pretty incoherent. Proposed edited title: "Does the 'cat' argument in query_posts fetch posts from subcategories as well as the given ID?" –  Jeremy Clarke Sep 11 '10 at 21:17
    
thanks Jeremy Clarke –  yogs Dec 20 '13 at 6:10
add comment

3 Answers

I can't comment yet, so I have to submit an answer. To map Joe Hoyle's answer on to query_posts, you'd do the following:

query_posts('category__in=1');

That'd would give you just the main category, without the subcategories.

It's not what the OP was asking for, but I found this via Google when searching for how to just show the main category, so others may find this too.

share|improve this answer
add comment

Yes, cat=x get's posts in x and all sub-categories, if you don't want this behavior doing category__in => array( x ) will only get posts specifically in that category.

share|improve this answer
    
To seal the deal you can also use category__not_in which lets you exclude specific categories, in case you want to exclude particular children but include all others. –  Jeremy Clarke Sep 11 '10 at 21:15
add comment

In short: Yes.

Your question is about the query_posts Wordpress PHP function. The link I've placed is the official wordpress codex documentation for that function.

For your example it states:

Display posts from only one category ID (and any children of that category):

query_posts('cat=4');

I hope this information is helpful. You find more infos in codex, the function is pretty powerful.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.