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?
- Exclude or Include category ids in WP_Query
- How to query only for products with status “in stock” in WooCommerce? [closed]
- WP_Query to show post from a category OR custom field
- get_posts with multiple categories
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Display recent posts from the same category as current post in sidebar
- How to filter by category in REST API, excluding posts also in other category term?
- Pagination custom query
- Order by two meta keys
- Counting number of posts with Category B in Category A
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- How to order category.php loop by ‘meta_value’?
- Function to check if author has posted within the last x days
- Use Transient API to cache queries for all posts in all categories?
- How can I display recent posts from a particular category in my header?
- Sorting Posts by custom field
- Shortcode returns escaped HTML tags
- Pagination Not working on Home Page with 2 Query
- Calling a custom excerpt function in a local loop
- How to get any tag ID
- Dynamically Override Fancy Title – Part II
- query posts in functions.php and update a field
- WP Query with multiple categories – passing an array works?
- Get posts using WP_Query
- wp_query display posts from same category of the post
- Finding post content that begins with a specific character
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- 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
- Best practice custom function, where to echo the variables?
- Searching through different categories on different pages code is not working
- How to get user_id from wordpress database inside ajax function?
- Get image of latest post from taxonomies/categories
- How To Remove/hide some specific categories from two different categories widget from sidebar
- 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?
- posts_per_page not working
- 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?
- List of the years with posts presented
- How to delete taxonomy term when a wordpress user is removed?
- Remove a specific category ID from related post
- Exclude category for main query and custom
- Complex Category selection as per user input
- Show all post for a given category
- Five posts from a category in footer
- The pagination on index.php doesn’t work on a first page
- Display posts from only one post form in custom query and exclude in main query
- How to get all unique categories for posts in loop?
- Display Featured Post by Categories and Avoid duplicated posts
- Cluster WooCommerce products in each Category Archive by Tags assigned to products
- Filtering posts from different categories into different section by doing WP_Query only once
- How to filter, restrict and return posts based on custom user meta information
- category query for pages not working
- Can we return all category (not post) with Custom Query Filter? [closed]
- WP Query using tax_query & meta_query
- Query posts intersecting tags and categories
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- Query posts from category A, and from either category B or C
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- Combining categories (Query posts with multiple taxonomy terms)
- Check if loop has any categories?
- Filtering out child category posts from parent category archive not working
- Display most popular in the past two days
- Exclude Category filter from Portfolio section
- meta_query not working as expected
- New WP_Query calls Pre_get_posts filter twice
- How to output the title of the blogs home page
- Inserting HTML to close and open divs in WP_Query loops
- Redirect to another page using contact form 7? [closed]
- how to access query string in wordpress?
- Limiting number of related posts
- Category ‘pad_counts’ & ‘parent’ conflict
- Merge two search functions for custom post type
- Finding WordPress Posts assigned to multiple categories
- Include posts from some categories while excluding from others
- Make a SQL query with wpdb in WordPress
- Combine results of multiple WP_Query to resemble single WP_Query
- 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
- Exclude authors IDs from WP_Query
- WP_Query Taxonomy categories filtering
- Hide products in uncategorized category from search results
- Loading two different AJAX requests on two different pages