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.

When I view a category page in 2010 theme, it shown posts categorized in:

  1. the category visible in url
  2. child categories of 1.

I want to restrict the results to 1. only. Please help.

share|improve this question
    
Codex says that WP_Query('cat=4') displays posts from child category by default. I couldn't find any direct way to filter child category's posts. –  afnrf Oct 10 '11 at 8:49

1 Answer 1

up vote 0 down vote accepted

And this is the indirect way I am using now. If there is any better answer please do share.

while ( have_posts() ) {
    the_post();
    $cat = get_query_var('cat');
    $categories = wp_get_post_categories(get_the_ID());
    if (in_array($cat, $categories)) {
        ...
    }
} // end loop
share|improve this answer

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.