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?
- Determine if page is the Posts Page
- How to get ‘post_content’ without stripping tags?
- Post preview mechanism architecture
- Post featured image column on admin post list page
- Search Custom Post Type Pages and Custom Fields in 2 Dropdowns?
- When and Where is `global $post` Set and Available?
- Counting words in a post
- Delete Child Posts
- In what sequence are the hooks fired when a post is “published”?
- Number of posts per page setting is not working?
- Include Sticky Post in Page Posts Count?
- Pagination for Pages and Posts
- How to choose a sort order (for posts) per category? (ideally when creating a new category)
- Remove inline width from figure
- How to lock a post or page
- orderby=meta_value_num creates duplicate posts
- Including new Javascript only after a comment is made
- Create post using JSON api plugin
- Query posts from different categories in multisite
- How to bring an old edited/modified post in the front of page?
- Display all months with posts and inside each month show the 5 latest posts
- Is there a way to backdate posts?
- How to make search for the custom post type?
- WordPress post tag & custom field
- posts_nav_link() not displaying anything
- Adding footers to posts?
- Injecting JavaScript into a Post with WP3.x
- Visual / HTML tabs vanished on editor
- Display post from specific date
- Why won’t my taxonomy query show up?
- Multisite – Get current post id
- WP_Query with ajax handler returns the same posts
- How to display posts on a static page? (like search loop)
- How to show single post page as home page
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Errors when uploading images in WP 3.5
- Get more than one author’s posts with REST API
- Unable to Add/ Edit Post in WordPress
- More then one menu items are assigned with “current-menu-item” class
- How can i delay reading posing in 3days for not logined user?
- Get attachments for posts that belongs to a specific category
- why are images not full size?
- Anyone know why wordpress converts some html entities to their numeric equivalents?
- How to Mysql select a list of posts with meta_values AND all relevant categories?
- Nested WP_Query breaking loop
- How to create wordpress class with post meta? [closed]
- In post.php how can I remove onbeforeunload?
- Custom taxonomy archive page problem
- post__in not working with pre_get_posts, but post__not_in does work
- Query posts and filter at query time by value of custom meta
- All posts display default index.html
- Blog page error ‘Index of /blog’
- tribe_get_start_time displays the current date and time on other post types than tribe_events
- How to get the latest URL of my blog?
- Hide parts of the post content after typing it’s name or searching it by category
- search content of pages and list in wp-admin
- get parent fields title, content excerpt etc
- Changing permalink of WordPress
- Rest API Paginate until all posts are imported
- Group first, 2nd, 3rd, etc posts by category terms
- Query to fetch custom taxonomy along with post title
- exclude particular category in api
- How to backup WP blog posts to computer, not new site
- Make categories appear random
- Single post shows post three times
- I want to change the WordPress comments file
- How to find the edit link of the WordPress Post from the URL
- Blog Page doesn’t show summary but full content
- Get posts from category from custom query
- Changing a users posts to drafts upon role change
- Show 5 posts and than 3 posts offset with pagination
- Alternative content between posts no repetition
- Start loop from specific post ID
- Connection dropped due to file size
- How to Get Position of a Post from a category and tag
- Custom author search
- Ajax – Post Categories and Load More
- My blog “page” used to show a list of posts, but now it’s just showing the page content?
- how to add a facebook page latest posts into my wordpress site
- Displaying categories items among posts
- unused post IDs
- Combining multiple conditional statements [closed]
- Is there a block to print post link standalone in a block theme?
- Export Posts Without Categories In An XML File