If you change your if
statement to use $query->is_main_query()
like the example on the is_main_query()
codex page, does that resolve the issue?
The nav menus are created by a query, so usually this problem stems from the pre_get_posts
interfering with the menus query. Hence, I wonder whether that check isn’t working.
Related Posts:
- Sticky Posts exceed posts per page limit
- Theres a way to use $query->set(‘tax_query’ in pre_get_posts filter?
- Modify Taxonomy pages to exclude items in child taxonomies
- How to Change Order of Posts in Admin?
- Obliterate the main query and replace it
- Post injection – how to exclude the original post
- sort child pages on admin
- Custom Table Column Sortable by Taxonomy Query
- Sorting posts that has a meta value first then the rest of the posts
- pre_get_posts on a page
- How pre_get_posts filter by roles in WP Admin
- Weird problem with pre_get_posts and $query->is_page()
- Sorting Posts by custom field
- Why is ‘pre_get_posts’ having no effect?
- Date Query to Pull Current and Future Posts
- pre_get_posts all posts and custom post type with certain tag
- Using Sessions to Filter Posts – bad thing?
- pre_get_posts and the blog page
- Archive by custom post type and custom date field
- pre_get_post filter returns results when there should not be
- Trying to exclude first 5 posts from the first page on the homepage
- Exclude a WordPress post from pre_get_posts if a field is null
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Why the ‘date_query’ is not working in ‘pre_get_posts’ hook?
- Using database meta_values to calculate new post order using pre_get_posts or a ‘request’ hook
- Only show certain post types in recent posts widget
- pre_get_posts for exclude category
- Sorting and limitation with pre_get_posts
- pre_get_posts: using tax_query only for certain post type
- pre_get_posts dont firing… Anybody knows whats the wrong with my code?
- Restrict Search Query To After Specific Date
- WP_Error not displaying errors
- Show all posts even if URL points to a single one
- Use pre_get_posts to sort meta_key by an array of values
- How to achieve post_status__not_in?
- Ordering by meta_key
- Using a pre_get_posts filter to search for multiple strings on all meta values
- Removing taxonomy query by pre_get_posts
- Sort the result of the main Query in shop page by a custom taxonomy
- Help ordering Post loop by two meta values
- Using different parameters for different queries with pre get posts in functions.php
- how to restrict posts_request filter to the main query only
- Automatically applying a pre_get_posts filter for child categories only
- How to override a query and display specific page by ID?
- pre_get_posts variables
- Another query in pre_get_post cause memory issue
- pre_get_posts having no effect on my category archive
- pre_get_posts returns non property object when using posts__not_in
- Override tax_query with pre_get_posts to include other term_ids on a single category
- $query->is_main_query() is causing query’s tax_query to be ignored
- Sorting search results with custom dropdown
- Menu disappears when meta_key changed [closed]
- pre_get_posts with multiple queries
- How to show the last and newest modified post in a custom category?
- Altering the main query using get_post_meta() in pre_get_posts
- Why query by specific date with variables doesn’t return same result that with harcoded integers?
- Sort WordPress Archive by multiple oderby arguments in pre_get_posts action
- Exclude post type with pre_get_posts?
- Exclude page by title for non admins
- problem with setting tax_query in pre_get_posts
- Sort categories by custom field in WordPress admin
- Order column custom date using pre_get_posts
- How to display remaining post ( in post__in ) if posts are less then post per page?
- Problem ID to exclude specific posts from category
- Modify Taxonomy pages to exclude items in child taxonomies
- Modify author archive query to combine two queries
- Change post order on archive to be displayed by most commented being ignored by theme
- Complex query using pre_get_posts
- Super confusing ‘pre_get_posts’ behavior with $query->set
- Having trouble with settings terms as array in pre_get_posts
- Override main query for page template
- New custom post type entries are not sorted correctly in admin using pre_get_posts
- Querying custom taxonomy on category-specific page is overwritten by function
- how to get content from other site and show it?
- Insert a variable in pre_get_posts
- Extend taxonomy term page with other posts
- Set a custom number of posts on the first page
- How do I sort post listing by child post count?
- Posts sortable column not sorting properly for custom field numbers
- Why does this query not SELECT post IDs like a normal query would?
- Please ensure me that I’m not crazy using the pre_get_posts [closed]
- How to pass >= condition filter to my year custom tax_query
- What is the proper way to use pre_get_post?
- pre_get_posts has php notice when not on CPT archive
- Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
- Sorting by Title for Post Archive Categories for Custom Post Type
- Duplicating event posts in wordpress
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- Sort posts by numeric value of custom field, and also show any other posts without that custom field
- When to use WP_query(), query_posts() and pre_get_posts
- Sort on meta value but include posts that don’t have one
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- Can I exclude a post by meta key using pre_get_posts function?
- Should I use Pre Get Posts or WP_Query
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Using pre_get_posts with WP_Query
- Sort results by name & asc order on Archive.php
- Using pre_get_posts on true pages and static front pages
- How do I set the default admin sort order for a custom post type to a custom column?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?