From a plugin or your theme’s functions.php file:
function wpse106861_mod_query( $query ) {
/* are we on the blog page ? */
if ( $query->is_home() && $query->is_main_query() ) {
/* get ID of news category */
$news_id = get_cat_ID( 'news' );
/* exclude posts in new from query */
$query->set( 'category__not_in' => array( $news_id ) );
}
}
add_action( 'pre_get_posts', 'wpse106861_mod_query' );
Update
As for the comment:
is_home
should return true on any blog index page, regardless of whether that’s a static page or your front page. You can check for the front page directly as well anyhow, by slightly altering the conditional:
if ( $query->is_front_page() && $query->is_main_query() )
Related Reading
Related Posts:
- How can I remove posts of a certain category from homepage after a specified time period?
- How to filter posts that belong to a specific category only if that is the only category
- pre_get_posts query between 2 dates (date stored in custom post meta)
- wp_list_categories() Exclude All Categories Except One
- Get current taxonomy and display query accordingly
- How do I display main query posts in random order using add_filter
- how to filter posts by category without page load (ajax) in wordpress?
- How to add a block to a category page?
- show only one category and filter by tag
- How to use in_category?
- Older entries link within a category page
- Multiple blog “feeds” in a single blog each with distinctly styled post pages
- Filters do not work when there are multiple (one works)
- I have a website issue I am trying to resolve
- What is the best way to publish News articles?
- Using ajax on editing a category edit page?
- Related posts by category not working right
- How to list recent posts in a wp nav menu?
- Set Default Category to Username
- Disable sticky option for specific categories
- Dynamic dependent Dropdown lists for categories, sub-categories and posts
- How to allow visitors to filter posts by multiple taxonomies
- How can I hide tags on a child-category page, if that tag has not been used?
- date issue with category post retrival
- Listing Specific Categories from Current Post with Depth
- How to make multiple sections in home pulling posts category wise?
- How to display two blog categories as separate sections on one page?
- How to make the first post in the loop be styled like a “new / featured” post?
- How to Mysql select a list of posts with meta_values AND all relevant categories?
- Redirect to another page using contact form 7? [closed]
- Display post category in foreach loop
- Single.php – Get Current Parent Category
- How do I stop the loop from repeating in my category template?
- Trying to alter the post_content through the_post
- get_the_category listing in hierarchial order
- Is it possible to add/tick a category to a post when it is created?
- Excluding posts not working
- Hide posts belongs to few categories in homepage
- Create new custom post and post category of same name
- why does wordpress ignore the post args?
- post category in wp_insert_post
- add to end of post in the loop with plugin
- Limit the number of posts a category can have – newest post goes in, oldest one drops out, possible? plugin?
- Add filter to the end of the post
- How to get subcategories from category slug?
- Remove current category from post but display all others
- How show categories in admin and get that selected to show posts in index
- Get post content with all filters applied, knowing post id
- Showing categories and subcategories with posts
- Change default category when I publish a post
- store posts_id of category into a varable?
- Adding bootstrap classes to video shortcodes
- Is it possible to filter the main loop to exclude posts from a specific category?
- How to display two random-post sections that are each under their own category
- How can you display all sibling categories to a post?
- Loop doesn’t exclude the specified category in home page
- query post limits
- post__in not working with pre_get_posts, but post__not_in does work
- Display posts of specific category term
- Widget that shows categories with posts numbers
- How to create a sub post?
- Post Image not displaying in category view
- How do I show posts from another wordpress installation?
- get posts from Custom Post Type & Category
- Category page when using static front page
- Latest posts by category — how to exclude current post?
- How do I include the category next to the title of a post?
- Relative number of post in category
- Modify posts listing at back end
- How to create a “latest news” page showing a list of posts from blog category
- Filtering posts on Post Administration Page by Week Number instead of by Month
- WordPress bulk category select when publishing post
- Prevent posts with certain post_meta to be edited
- Exclude some categories from listing on the current post
- How to show a custom taxonomy in the theme?
- How to import nested categories from XML file?
- how to hide empty fields of post category description?
- Change the default blog post post attribute template name from “default template” to something else
- how can i display my posts alphabetically?
- Hook for changing excerpt content when excerpt not set
- if in category but only with post meta
- How to get post with associated categories and tags names instead of ids with rest api?
- Is it possible to add a shortcode below post title?
- Post filtering is returning blank page
- Display a mixed list of posts and media
- Migrate posts from category and sub-category via SQL
- Parent category / child category posts
- Posts Missing in Dashboard after update
- How to enable custom Shortcodes in Post Category Description? [duplicate]
- Sort by last word in title
- Display post number by category
- Filter WooCommerce archive pages by an additional category
- singular posts using archive styling
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Change Post Title For Specific Category
- How include css class based on post ( in loop ) slug?
- Display selected categories onto post page
- How to call posts under a specific category on static front page?
- Custom tax_query filter not working for Woocommerce product categories
- Custom Post Limit for homepage only without plugin?