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
- Could not insert term into the database
- How can I get category ID by category name?
- Randomise results from a category page?
- Adding Custom User Profile data based upon Categories
- Only show category to certain user levels without plugin
- Using a portfolio_category slug in wordpress URL
- Nav menu category links not showing
- Making a tourism information website [closed]
- Exclude a category from the_category in the single post page
- Display category posts before others category custom query [closed]
- Get Prevous/Next Post Specific Category Without Excludes
- Pagination is not working properly in Product Category/Tag pages
- add_rewrite_endpoint returns 404 on archives
- Multiple category archive page
- How to display post type and category links in foreach WordPress code
- Get posts under a category with SQL
- Randomly load categories with latest post
- Is it possible to remove from default category widget?
- Combine “category search order” with “don’t display child posts”
- category__not_in and id values from variable
- If x comments in a post move post to category y
- Adding additional content on post depending on post categories
- Root category template?
- Add Date & Author Meta to Category Archive Page
- A dropdown with checklist
- Custom meta boxes ID prefix showing on first category but not others
- Show Secondary Sidebar on Category pages (archive)
- 3.1 post formats and specific categories/custom taxonomies
- Duplicate new categories across multisite network
- Template category.php with page (no posts)
- How to set featured image as background for a specific category?
- Query posts from newest category
- Code to display category-specific single.php is overriding normal single.php, too
- Media Library filter returns undefined function get_current_screen
- Display all subcategories for a product category in woocommerce