Yes your code will fail, but not because the above answer, but because this isn’t the page you ask for.
As you wrote, you set the page “videos” to be the page where all the posts are shown.
When a page is set as a blogpage, WordPress will use home.php or index.php according to the template hierarchy to display the blogpage, not a page template. This page is regarded as the home page, so is_home()
will return true on this page
So, to exclude the categories, you need to use this conditional:
function exclude_category($query) {
if(is_home()){
$query->set('cat', '-42, -43');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
Happy Coding,
Kuchenundkakao
Related Posts:
- Exclude Tags from get_the_tags
- is there a quick way to hide category from everywhere?
- Exclude category from category archive
- Multiple arrays in post__not_in parameter
- 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
- 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
- Alter secondary loop to exclude posts from current page category
- Exclude file from theme editor
- Dynamically excluding current page id
- Exclude a specific tag from the get_the_tags list
- Exclude subfolder from WP-redirect works with html but not php files
- How to exclude shortcode from specific page IDs if it’s set to global
- Query Ignoring ‘exclude’ Parameter?
- How do I exclude posts by custom field value?
- Exclude specific taxonomy term when using wp_get_post_terms
- Exclude custom taxonomy tag from loop
- How to exclude posts from a category when using this particular format
- 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
- Query Posts Exclude Entire Category
- Exclude category from fucntion
- WordPress category widget only show categories with children
- Remove ID page from wp_count
- Combine get_page_by_title to exclude pages from wp_list_pages
- Individual post. Meta_key, taxonomy or post status for separation?
- Next Posts Prev Posts for Standard post format only
- ‘exclude’ argument is not working with get_posts for a custom post type
- 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
- link to a random custom post while excluding current post
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- wp_list_pages() exclude category
- Include posts from some categories while excluding from others
- How to exclude Sticky from Recent Post?
- Exclude posts by post meta value
- Exclude pages by menu order
- Exclude Specific Tag On Homepage
- Exclude Category ID in function
- Woocommerce filter function not updating
- How can I exclude a specific ID from this line of code?
- Exclude latest post from WP_Query taxonomy term loop
- Exclude posts with certain meta data from search results
- wp_list_categories not excluing multiple ids
- How to exclude posts from category posts count
- Exclude category from foreach loop
- 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
- 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
- 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?
- How to display elements of different post types?
- How to have a category not show up in query post with page panigation?
- Customize category query in widget
- 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