is_category('category-name')
won’t work until after the query is run. If we check source code where those notices are generated, we can see that it’s using get_queried_object
, which gets populated with the results of the main query, and at the pre_get_posts
stage will still be empty.
As an alternate, check the contents of $query->query_vars
, which will be an array of query vars parsed from the requested URL.
Related Posts:
- is_category() in pre_get_posts strange error
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Include posts from feature category in pre_get_posts
- Category param redirect to post type archive
- Rearranging posts based on categories
- How do I edit pre_get_post for the category the user is currently in?
- Custom Query to search through categories
- How to query all posts of a specific category, and any other category combination
- Query the Loop without breaking it
- How to Check if a Child Category is Being Queried
- How Do I Merge Categories With phpMyAdmin
- If newest post of category is newest post in general, skip first post of category
- Disallow categories from this MySQL query
- How to display posts under a specific subcategory of a given category
- get_the_category and echo out link to child-most/deepest category
- query in category.php repeats itself
- Display posts separated by Category in Author’s page
- How to get related tags based on a category?
- Show popular post by category code
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- How to get latest posts from each category in regular order
- category pagination got broken suddenly
- How to query categories with Advanced Custom Fields?
- Where and when does WordPress invoke routes
- And/Or Category Query
- Exclude category by slug in pre_get_posts?
- Exclude category from query
- Overriding default calendar to show posts from a category
- Filter WooCommerce archive pages by an additional category
- Custom tax_query filter not working for Woocommerce product categories
- function query_posts disabling current_page_menu class
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- Using in ‘category_name’ in ‘$query->set();’?
- custom query for both category and pages using global $wpdb;
- Get categories of queried posts
- Query from multiple category (and)
- How to display posts from specific category using get_option function?
- SQL query to get posts from multiple categories but not in a category
- Conditional category query breaking?
- How to filter post from categories only if the posts appears in one of them, not the other?
- Category name for all posts getting assigned to a single random post
- Show Posts via cat+cat in URL that are in both Categories doesn’t work
- `offset` WP_Query argument dont work via `pre_get_posts`
- List of post categories only associated to another custom taxonomy
- Sort categories by custom field in WordPress admin
- how tho change number of posts in loop from specific categories
- Change post category within pre_get_posts
- Get category from slug list
- Issue with WordPress category search
- Querying posts from two different categories while looping inside another loop
- how to get postmeta info based on multiple categories?
- Too many categories drastically slow down my website
- How to get posts from many categories using WP_Query
- Is it possible to query the result of a query?
- show posts found in multiple categories via category_name query string?
- Help with SQL query, how to add taxonomie terms with value stored in options?
- Match two taxonomies to display a specific content
- Category slug in in loop always the same?
- Create Cross Promoting Categories in WordPress Using ‘pre_get_posts’
- display certain category on custom template page
- Detecting top parent category fails on home page
- How to use Greek characters/letters in a query?
- Displaying posts by year
- wordpress category.php query for featured news item, broken pagination and repeating posts
- How to show posts of a specific category
- How to get parent and child sub category (Taxonomy) order to display
- How to query by subcategory and, if there are fewer than 10 posts in that subcategory, fill out with posts from parent category
- How to make query loop block dynamic
- Link For Portfolio Categories
- Display Some text in some specific category not all category
- Get posts base on category ratio of more then two categories
- displaying one category on one page
- Ajax Category add doesn’t update the list table custom column
- In ACF, how to show custom category selection tab upon selecting a main category
- Icon images across multiple categories
- WooCommerce – Get products from category right before deleting category
- omit categories from main navigation menu
- Change Category Base For Custom Post Type or Posts Page
- Category name as page title
- Is there a way to order categories?
- Confused about category.php template – not working
- How to test if the post is in a primary category
- How to hook into creating a category?
- Pagination does not work with query_posts()
- Categorizing Just Imported Posts
- Bulk Change WordPress category Slug
- Adding Category in WP_Query Not Working
- Hiding by default posts in given category except for some cases
- Default URL for category dropdown select option
- Post url rewriting for posts with certain category
- How to get the term id inside the start lvl method of category walker?
- How to use categories, sub-categories and customize navigation view
- Hide empty category on woocommerce
- Media Library Category Exclude Tree
- Media Library Categories
- Hide post category name wherever it might be mentioned
- Multiple if statements with else for get_the_category [closed]
- When category name and title are the same … WP will select archive.php instead of single.php
- Exclude category from WP_Query args not working
- How to apply wordpress ‘with_front’ = false for categories?