Adding $query->is_main_query()
to your if
statement in pre_get_posts
function. This will check if it’s the main query for the page, and not a custom query.
Related Posts:
- ajax category filter
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- How to load a script code only in posts?
- How to get post id of static front page?
- How to query only for products with status “in stock” in WooCommerce? [closed]
- get_posts with multiple categories
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Pagination custom query
- How to order category.php loop by ‘meta_value’?
- How can I display recent posts from a particular category in my header?
- Sorting Posts by custom field
- Pagination Not working on Home Page with 2 Query
- How to get any tag ID
- WP Query with multiple categories – passing an array works?
- wp_query display posts from same category of the post
- WP_query category__in not working, only pulls from first category
- WP_Query order by date in meta_value
- How get posts from a subcategory of a category by name?
- get complex results set according to category structure
- Searching through different categories on different pages code is not working
- How to show in search results posts with a particular tag in a particular category?
- How to select posts from one category but exclude posts in another category?
- Get Category Archive Template Name Dynamically
- WP_Query arguments to fetch custom post type posts which are in certain category?
- How do I reset this wp_list_categories query?
- How can you get first post, last post and post count in a category?
- Exclude admin from WP_Query Contributors
- How can I remove posts of a certain category from homepage after a specified time period?
- How to get count of posts assigned to given category?
- Multiple Loops Inside a Function
- How to show subcategories using loop?
- How to delete taxonomy term when a wordpress user is removed?
- Remove a specific category ID from related post
- Five posts from a category in footer
- Display Featured Post by Categories and Avoid duplicated posts
- Filtering posts from different categories into different section by doing WP_Query only once
- category query for pages not working
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- Check if loop has any categories?
- Display most popular in the past two days
- New WP_Query calls Pre_get_posts filter twice
- Inserting HTML to close and open divs in WP_Query loops
- Finding WordPress Posts assigned to multiple categories
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- Loop doesn’t exclude the specified category in home page
- Error with function in functions.php?
- WordPress Custom Search Form Displaying Unexpected Results
- wp_query is showing posts from other categories
- WP_Query Taxonomy categories filtering
- Loading two different AJAX requests on two different pages
- Post not populating for custom post type based on category selection
- Multiple meta_key ordering with pre_get_posts
- How to display a list of posts in same child category as current post
- How to exclude a category name from showing?
- Loop categories by recent post
- Get the child category ID of current category
- Related Posts Excluding Certain Categories
- Trying to get property of non-object in: $wp_query
- Post incorrectly excluded when using “category__in”?
- Related posts by current posts child category
- Filter products on category AND tag
- query hook parse_tax_query function takes no effect
- How can I have sticky posts while ALSO showing posts from a specific category using one WP_Query?
- How to use the Term Object from a custom select field in a query
- Pagination repeating posts on search results
- Categories In English version showing not canonical URL, instead shows query search result
- How to check if logged in user have pending custom post?
- What code to use in an array to call the current sub-category?
- Custom WordPress post query for displaying time-released content on website
- Related categories order posts by category
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- Where my home page and font options has gone?
- Pagination for Category does not work
- Display All Top Child Categories / Taxonomy
- Query post by Category and custom file (ACF)
- How to upload 3 attachments to current post?
- WP_Query showing all posts, except from category X, unless it’s also in Y
- Single query for multiple categories
- Display 3 levels of categories on page
- Filtering ‘Featured’ posts from a batch of category IDs
- Get post Number with local loop and template
- Help displaying related categories
- Calling a function with WP_Query only ever brings the first result
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Category Archive not working for pages
- Show full category tree for a year with all post titles?
- Display post list within category list sorted by name [duplicate]
- Create multiple sections for all categories and then queries all the posts for each of those categories
- Hiding all posts/products/pages from a site based on a custom taxonomy/domain name
- Show only one category in main query, issues on tag page
- Related posts with WP_Query
- Main loop querying current template’s info only in custom category archive pages, not my posts
- query_vars category_name only display one catgory out of multiple categories
- List categories using WP_Query
- Filters do not work when there are multiple (one works)
- Variations as Single Products [closed]
- Advanced Search – Is this possible?
- How to get post taxonomy url and name 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