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.

  • 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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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