There are a couple of problems with your condition:
A single query cannot match all of your conditions – it can’t be a tag
as well as search
, for example. You need to use ||
(or) and possibly nest – so for example,
if(!is_admin() && ($query->is_home() || $query->is_search())) {
This says, “if we’re not in the admin area AND either it’s a home query or a search query, then do this.”
Also, some of the is_
conditions you’re trying to meet aren’t the way you test the query. is_front_page()
cannot be called because the query isn’t set up yet – but is_home()
can. Read up in the documentation to learn more about which conditionals are valid, and then you can try a simplified query first – such as if(!is_admin())
to make sure it’s running – then add additional conditions one at a time so you can tell which one specifically is causing you problems.
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
- Obliterate the main query and replace it
- Post injection – how to exclude the original post
- Adding meta_key via pre_get_posts causes navigation to disappear
- 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()
- 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
- Why the ‘date_query’ is not working in ‘pre_get_posts’ hook?
- Only show certain post types in recent posts widget
- pre_get_posts for exclude category
- pre_get_posts: using tax_query only for certain post type
- Restrict Search Query To After Specific Date
- WP_Error not displaying errors
- Show all posts even if URL points to a single one
- 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
- 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
- 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
- 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
- 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
- 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
- Duplicating event posts in wordpress
- Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
- Varying the number of posts per page from the first one
- How to alter query order direction using $query->set(‘order’, ‘ASC’); inside a pre_get_posts filter?
- Meta Query “IN” doesn’t work with ACF checkbox filter
- pre_get_posts with WooCommerce Shortcode Query
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- Including only current user’s posts in search
- Advanced or not so advanced pre_get_posts query
- Showing posts from different categories and from custom post type
- Custom Post Type Archive Error, Takes Last Post as Title and Doesn’t Work
- WordPress Screwing Up ‘orderby’ => ‘meta_value_num’ in ‘pre_get_posts’
- Can a link in WordPress contain a query string that is picked up as $_POST
- Child pages not affected by orderby
- pre_get_posts to hide everywhere posts from “Archive” category
- Sort categories by custom field in WordPress admin
- Order column custom date using pre_get_posts
- Setting user permissions per post
- How to hide private posts even if user is admin
- How to show only specific category post by user role without plugin and restrict all other cats
- How order by works?
- WP search in metadata post
- pre_get_posts with multiple post types AND a meta_key
- How to use get_pages( ) correctly with ‘child_of’ to replace page with child page
- wp_query – Modify $query to include duplicate content
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Problem to show custom post type in archive page category wise
- Adding custom post types to the default loop, yet only posts that has terms from the core taxonomies
- Pre_Get_Posts order DESC not registering
- Avoiding page loop
- pre_get_posts causes Custom Posts appear under ‘Pages’ menu
- How to put posts with some taxonomy on top of others in `pre_get_posts`