Don’t change your template, and please do not use query_posts.
Add this to your function.php:
add_action('pre_get_posts', 'filter_out_children');
function filter_out_children( $query ) {
if ( is_main_query() && is_category() && ! is_admin() ) {
$qo = $query->get_queried_object();
$tax_query = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $qo->term_id,
'include_children' => false
);
$query->set( 'tax_query', array($tax_query) );
}
}
Related Posts:
- Skipping first 3 posts in wp query
- Exclude posts with specific meta_value while sorting by a separate meta_value
- Filter Posts by Excluding Categories
- How to set post expiration date and time and move the page to archive after expiration [closed]
- how to get posts ids inside pre_get_posts filter?
- How do I exclude the current post from listing in recent posts
- Exclude the first ‘n’ number of posts of a tag from home page?
- Excluding posts not working
- Loop doesn’t exclude the specified category in home page
- How to exclude posts that already appear in the main loop, from the category loop
- How to get post with slug and exclude categories
- Exclude post category in a blog page
- Use posts_where to exclude posts ids from wp_query
- Conditionally exclude post from specific category on home page sidebar?
- Excluding category from post navigation in WordPress?
- Exclude a ‘portfolio’ custom category?
- When is the ‘post_content_filtered’ column in database cleared by WordPress?
- Is it possible to bold certain words in a post title?
- Displaying the category name of a custom post type
- How to disable Uncategorized category URL?
- Add role that restricts user to post in specific category
- Most efficient way to insert a post outside WordPress?
- Display content from a specific category
- Delete posts from a post type automatically via Cron
- Template file for static posts page does not get loaded?
- Group Posts by First Letter of Title
- Display most recent post in category instead of archive?
- How do I programmatically add an image to a post?
- problem to delete page
- Display the latest posts, published in the last hour, with WP_Query
- same template for multiple custom post type single
- Get user’s most published categories
- Allowing the SoundCloud player to appear in a post excerpt
- Converting multiple loops into one single loop with pagination
- Run a function when post is deleted?
- Server-side sorting of posts
- Exclude posts w/ specific post_meta on Rest API endpoint
- How To Remove Certain category Posts From the Blog Page
- Add icon/badge next to posttitle of specific category
- How to change wordpress dates to native language (even if the languge not available i wordpress)
- How Can I Query a Specific Page From a MultiPage paginated Post
- Too many connections to server
- delete_post hook – deleting multiple items
- WP_Query orderby not working with meta_value_num and menu_order
- Custom Post Archive Page not working
- How to switch wordpress post status between publish and schedule in MySQL?
- Shortcode to display the latest news article within a page
- How to make the first post in the loop be styled like a “new / featured” post?
- Help diagnosing scheduled post problem with transition_post_status
- Archiving posts in wordpress
- User Selectable Delete of Pages
- Develop Admin Panel Page
- query post limits
- is_page() and is_page_template() not being differentiated
- Lock post editing to one user at a time – wp_check_post_lock
- where to download bb-ratings plugin for wordpress?
- Can’t give tags rels
- Display password protected posts to logged in users
- How to show content without excerpt?
- Get attachments only for this post
- Add hero image to home page (blog format) via the dashboard
- All categories displays the same posts
- Having pages after specifying post_type post
- I want to show my post for limited time, how is it possible?
- Query function not executed between element [closed]
- Microformats in a single post – layout conflict
- Conditional css for custom post type
- Display most recent posts in category with Twenty Ten theme widget
- Your ideas on my though “delete or move all of the posts in a specific category when 3 days are passed”
- How Can I Always Display A Particular Post First Using WP_Query?
- How to remove the ManageBlocksMenuItem in the ToolsMoreMenuGroup in the Gutenberg Editor?
- Different background colors for posts with WordPress
- How to preserve HTML from posts in RSS feed
- Menu does not foward to the linked posts
- Run a function when a custom post is update?
- WordPress Post ids big increment
- Add a second rich text input to post editor, and make that content available in post template
- How to get post creation date?
- How to set the post permalink using the WordPress REST API?
- Multiple post in One Loop in wordpress
- Post images are not displayed in media library
- Order posts inside bootstrap card columns
- Save ACF with a save button on a post
- How do I customize the post page
- Clicking on a Post takes 10+ seconds for the server to respond, Pages will respond immediately
- Schedule image post on download
- Show posts in a parent directory [duplicate]
- How can we print out total number of posts filtered by post type and category?
- All my posts don’t show, only the headline is displayed on the homepage
- How to prevent people from seeing an attachment to a scheduled post that’s released in future?
- How can I access my posts on my wordpress site, now I’ve lost the domain name for it?
- Page not loading content – Body archive – page
- Daily posts like an archive
- Retrieve latest post by multiple categories with ID
- standard wpGallery for post won’t work
- Why is $_POST Empty in Profile Edit Admin?
- How remove “recent comments” title without modifying code? [closed]
- Return All Post from publish to draft [duplicate]
- Get posts after calculating meta key
- Articles show some of text [duplicate]