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
- When to use WP_query(), query_posts() and pre_get_posts
- Get all posts which was posted on X Days WordPress
- Finding WordPress Posts assigned to multiple categories
- WP Query – order posts by meta field first and then order the rest
- Include posts from some categories while excluding from others
- pre_get_posts – Trying to get property of non-object warning
- How to provide meta_key array to wp_query?
- Combine results of multiple WP_Query to resemble single WP_Query
- Easy way to write complex queries in wordpress
- Filter post query to only show direct children of category
- Order post type by sum of two custom fields
- get_posts output always same post
- WordPress Custom Search Form Displaying Unexpected Results
- Query_posts works when appending via AJAX call wp_query doesn’t?
- Use WP_Query or query_posts() or get_posts() for optimizing a site?
- Pagination on category.php and tag.php not working
- How to create custom query by keyword in post title?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Conditional operator OR not working with custom fields
- complex get_posts() query to select child pages
- Display if author page is author page of current user
- Get posts that do not have the same tags as current
- queried_object using pre_get_posts gets notices and warning
- date_query in pre_get_posts out of memory
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- wp_query is showing posts from other categories
- Should I reset $wp_query?
- WP_Query Taxonomy categories filtering
- Filtering posts by archive showing all years
- Hide products in uncategorized category from search results
- Posts Query | Query to only show sub categories
- 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?
- Multiple meta_key ordering with pre_get_posts
- Sorting search results with custom dropdown
- Posts query according to meta box date
- How to echo woocommerce category name
- pre_get_posts – editing query, tax_query
- How can I comment comma-separated array values?
- How do I add a relation parameter to my filter query?
- How to display a list of posts in same child category as current post
- Slider won’t work with custom query
- WP_Query with one category in args shows other categories
- How to exclude a category name from showing?
- Loop categories by recent post
- How order posts from category by date and comment count?
- Get the child category ID of current category
- Child pages not affected by orderby
- How to get posts by category and by choosing a taxonomy term?
- Related Posts Excluding Certain Categories
- Getting the permalink to the latest post from a category
- How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order
- What is wrong with my WP_Query Arguments?
- Get next/prev image/attachment in time with date query
- 2 queries with counters
- Show single posts date, in a page of posts
- Post archive for certain post format
- Max Posts and Memory Limit
- specific post is not excluded from the loop
- Why doesn’t my WP Meta Query return any results?
- Multiple Query_Posts
- Paginate pages with dynamic query
- Posts of specific category on page and excluded from index.htm
- filter posts by meta key with pagination
- new WP_Query issues
- Trouble Making WP_Query paged
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Creating ‘posts page’ loop based on the page itself
- Determine if ID is page or post and query the ID
- How to query for a page, get data, then query for child pages of that page
- Custom template for password protected page
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- WP_Query Class custom field parameters
- How to apply pre_get_posts to a custom query?
- Add AJAX “Load more” on custom query block
- Posts limit on homepage (genesis framework)
- Magazine style frontpage with multiple categories/loops and no duplicate posts