The is_category function checks the queried object. Since this is in pre_get_posts, the query has not happened yet.
Check the other parameters to find if the query is going to be for cat 5, not if the results are for cat 5. Try ->get(‘cat’).
Related Posts:
- When to use WP_query(), query_posts() and pre_get_posts
- Using is_main_query to select custom post type on certain page
- Sorting Posts by custom field
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- Searching through different categories on different pages code is not working
- List of the years with posts presented
- Store sticky post’s ids in a transient
- Five posts from a category in footer
- Display posts from only one post form in custom query and exclude in main query
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Creating attachments archive in tags and categories
- Elementor posts custom query based on tag [closed]
- `offset` WP_Query argument dont work via `pre_get_posts`
- Filter products on category AND tag
- query hook parse_tax_query function takes no effect
- pre_user_query vs pre_get_posts
- How do I stop the same post showing multiple times in a archive?
- Pull posts from all categories if quantity is not met?
- Show full category tree for a year with all post titles?
- Modify query to exclude certain ids and certain parents and its corresponding children
- Display post list within category list sorted by name [duplicate]
- query_posts problem – need help
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Exclude or Include category ids in WP_Query
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- How to uniquely identify queries?
- Display recent posts from the same category as current post in sidebar
- “pre_get_posts” firing on every query
- WP_Query ordered by custom field that is a date string?
- Use Transient API to cache queries for all posts in all categories?
- How to use filter hook posts_join for querying taxonomy terms in posts_where?
- How to Get All Posts but the Private ones?
- Single page theme that uses pages for the content
- WordPress custom search form with pre_get_posts not work
- Display one latest post from multiple categories
- order by multiple meta keys in pre_get_posts
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- Too many posts cause slow load when paginating
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?
- Query post with meta_query where date is not in future
- Formulate a url to show posts with both taxonomy terms
- Offset Page Loops and Pagination
- Query with custom taxonomy not working
- pre_get_posts order by not working
- Query posts by specific word on title
- Adding a parameter to the default query
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- WP_Query last five posts, simply ordered by meta_value
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- How to change main query based on post meta
- WP_Query condition affects posts_per_page count
- add active class based on permalink and url
- Slow page loads due to WordPress Core Query
- Two loops on archive page
- How to order posts by title after they have already been sorted by category
- Combining categories (Query posts with multiple taxonomy terms)
- Limiting number of related posts
- Category ‘pad_counts’ & ‘parent’ conflict
- Hide elements outside loop based on query
- Advanced WP Query and/or
- Get all posts which was posted on X Days WordPress
- WP Query – order posts by meta field first and then order the rest
- How to create custom query by keyword in post title?
- Display if author page is author page of current user
- How to load a script code only in posts?
- WP_Query – How to get all posts of specific days of week by custom field date?
- How can I comment comma-separated array values?
- 2 queries with counters
- Multiple Query_Posts
- Creating ‘posts page’ loop based on the page itself
- Use get_cat_ID to retreive multiple category IDs
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- Duplice post with standard WP loop – fixed by using query_posts() instead
- ElasticPress is (aparently) messing with my search filters
- How to display the category dropdown auto search list when key press?
- What code to use in an array to call the current sub-category?
- Get categories within specific term
- Order by meta date with a thousanth of a second defaults to post order
- Custom query for custom post type not getting correct post ID
- Exclude parent categories from recent posts list
- WP_Query showing all posts, except from category X, unless it’s also in Y
- Adding Category in WP_Query Not Working
- Merge two queries and remove duplicate
- display all posts from category with and without terms in chronological order
- Seach and categories not working when ignoring sticky posts in main loop
- posts_per_page increment additional post
- how to exclude store in clipper theme wordpress code php
- Display Count of posts
- Adding a Theme Customizer Control for Posts_Per_Page
- Looking for a way to exclude frontpage and nav menu from query filter
- Help in query for list links
- WordPress pagination returns the same posts
- query only direct child and sub-terms of a current term archive
- the_excerpt() not working in custom archive
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- Pagination only showed when no category is set in wp_query
- Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2