pre_get_posts
is the right hook for this
since i just did category exclusion in another answer i will post it here too.
Exclude the category from the WordPress loop
based on the codex sample:
http://codex.wordpress.org/Custom_Queries#Category_Exclusion
add_action('pre_get_posts', 'wpa_31553' );
function wpa_31553( $wp_query ) {
//$wp_query is passed by reference. we don't need to return anything. whatever changes made inside this function will automatically effect the global variable
$excluded = array(272); //made it an array in case you need to exclude more than one
// only exclude on the front end
if( !is_admin() ) {
$wp_query->set('category__not_in', $excluded);
}
}
Related Posts:
- Exclude Tags from get_the_tags
- Exclude category from category archive
- Multiple arrays in post__not_in parameter
- Exclude some categories from the post page
- Don’t execute function on specific posts
- using pre_get_posts to exclude
- problems exluding categories
- Better way to exclude category output for post/pages?
- Disable the link on certain pages
- post__in and tag__not_in conflict
- How to exclude one category
- How to exclude a category in the following Code?
- Exclude Categories from wp_list_categories()
- List post wit the same category but exclude parent
- Display 1 category only with get_the_category (by ID or slug)
- trouble with my loop
- Get first category only and excluding one
- How do I exclude plugins from getting automatically updated?
- Exclude Current Post from Recent Posts Loop
- Exclude the category from the WordPress loop
- Skipping first 3 posts in wp query
- how can I use WP_Query to exclude a specific tag.?
- Exclude categories from Loop, queries, widgets, post navigation
- List posts by category exclude current post
- wp_list_categories exclude not working
- Exclude ALL posts from sub categories
- Excludes posts that don’t have attachments in the_content()
- Excluding a category from next and previous post links
- How to exclude/filter a tag from get_the_tag_list()
- Exclude post_type from admin comments_list
- Exclude Custom Post Type & Pages From Auto-Tag Function
- Add exception for specific tag
- How to exclude categories from recent posts, recent comments & category widgets?
- Alter secondary loop to exclude posts from current page category
- Exclude posts with specific meta_value while sorting by a separate meta_value
- Exclude file from theme editor
- Dynamically excluding current page id
- How to exclude a directory from WordPress permalinks in a Multisite environment?
- is there a way to retrieve posts that do not have a featured image assigned?
- Exclude category from Tag Template
- Query: offset post list, unless it’s a specific category
- exclude post from displaying in loop if it is in a category, but not in many categories
- Exclude Posts From Specific Category from Next and Previous post links
- exclude categories from search results
- Exclude category from fucntion
- Remove ID page from wp_count
- Combine get_page_by_title to exclude pages from wp_list_pages
- Next Posts Prev Posts for Standard post format only
- ‘exclude’ argument is not working with get_posts for a custom post type
- Avoid repeated post on page 2 when excluding one on page 1
- Exclude custom taxonomy term posts from custom post loop
- Exclude posts with taxonomy term from appearing on home page query
- Exlude pages from wp_list_pages
- Exclude post format from get_posts
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Exclude current post from an array of posts?
- How to exclude Sticky from Recent Post?
- Using WP_Query and Query_post for the loop?
- Exclude posts by post meta value
- Exclude pages by menu order
- How can I exclude a specific ID from this line of code?
- Exclude page from loop results
- wp_list_categories not excluing multiple ids
- How to exclude posts from category posts count
- Exclude category from foreach loop
- Exclude all subcategories in the_category (post)
- Exclude categories by ID
- remove term from custom taxonomy list
- WooCommerce Hiding A Certain Category From Being Displayed On Single Product
- Terms from current post custom taxonomy — excluding parent and only from a single parent term
- Homepage custom recent news
- gallery shortcode exclude not working
- Exclude the category in WordPress
- Conditionally exclude post from specific category on home page sidebar?
- Search results to be only posts & children of page ID
- exclude certain categories form archive widget
- Hide/exclude certain tags under single post
- Exclude a category and post_type from wp_query
- Only Show Excerpt After First 3 Posts
- Skip latest 3 posts from loop
- Create a list of pages excluding children of selected page
- Exclude category and post from loop in custom category.php
- Exclude first image from a Woocommerce image gallery
- Excluding category from post navigation in WordPress?
- Multiple Taxonomy post query with exclusion
- Exclude Posts from a Widget
- $query->set( ‘post_type’, ‘post’ ); not working
- How to exclude one post format from search result?
- Category menu that filters out empty categories
- How to display elements of different post types?
- Problems with explode [closed]
- How to have a category not show up in query post with page panigation?
- Customize category query in widget
- show 10 most recent custom post types excluding the one(s) from specific custom taxonomy
- Excluding cateory not working on my site. how to solve this? [closed]
- exclude page element from specific pages
- WP Query Obj: Set value to be unequal | Hide media by admin
- How to define category ID in an array?
- Exclude pages by custom field (with yes/no) storing wrong data?
- Exclude a category ID from the following function