WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. – a_fan Oct 10 '11 at 8:49
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.