You are slightly confusing $wp_query
global variable with WP_Query
class/objects. $wp_query
is an object instance of WP_Query
, but not every WP_Query
object has anything to do with $wp_query
global.
Function version of conditionals, such as is_search()
, always act on main global query. You shouldn’t use them inside filters, since global state might be one thing and the query you are actually in another.
Inside hooks you should be always making checks on instance of query provided, via its methods. For example $query->is_search()
.
Related Posts:
- Want to redirect if search query match exact title of any post
- is_search was called incorrectly
- Can I force WP_Query to return no results?
- Post_count only shows the number of results per page
- WP Query where title begins with a specific letter
- Is it possible to completely stop WP_Query retrieving posts?
- Search custom taxonomy term by name
- Hook/action after WP_Query gets posts to query custom tables for post-related meta
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Tracing the life of a query
- Overriding The Loop with filter or hook
- new WP_Query() – what is the earliest valid hook?
- Identify which loop you are hooking into; primary or secondary?
- Pagination not working for Custom search form & custom result template
- How to support multiple search terms query within one process?
- Pagination broken when merging search results with additional WP_Query
- Custom search form with empty parameters
- How to search by title or tags exclusively?
- WordPress search exact match
- Pagination wont work with search results template [duplicate]
- How do I search WordPress by different fields without a plugin?
- Multiple keyword search
- Using next/previous_posts_link with customised search
- WordPress custom search form with pre_get_posts not work
- Search – Ajax – Alter Query Parameters with Pagination
- Add custom search results to main WP search [duplicate]
- Multiple search queries on one page
- tax_query shows no results if nothing is selected
- Best practice custom function, where to echo the variables?
- Searching through different categories on different pages code is not working
- WP Query search for attachments and their exact title
- WP_Query’s “request” SQL Query
- Including only current user’s posts in search
- How to change posts order on Category and Tag archives?
- How do I search inside specific taxonomies in WordPress
- Modifying the Search Results
- Custom category search box for WordPress
- Refine search results using WP_Query
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Search Posts with Custom Fields as query
- Complex date range with WP_Query and BETWEEN
- Creating a custom search for a specific post type
- Custom Search Result Page displaying only 1 result.
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- How to choose between hooking into per_get_posts or into parse_query
- How to loop for every result found in the_content() when using the search query?
- Assigning a meta_query value based on regexp to wp_query fails
- How to use filter hook “the_posts” with a function that refers to $this?
- How to delete taxonomy term when a wordpress user is removed?
- showing all search result in one template
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- Is there any advantage of using default WordPress Search instead of creating a custom one?
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Search pages that are a child of the current page
- Include tags in WP_Query
- Search for multiple tags?
- Custom Search Not Consistent with Results
- wp_query ‘s’, search filter with pagination is not working
- Editing the default wordpress search
- How to use wp_query to post count by search term > group post count by date > convert to json. (ex. result 12-21-2020 – 343)
- Multiple Search Terms WP_Query
- How to filter, restrict and return posts based on custom user meta information
- How to use the query hook/filter?
- Set global $wp_query/$post variable for dynamic page generation
- Extend product search with meta in WooCommerce
- WP Query Args – Title or Taxonomy Value
- Display filtered results into custom page
- WordPress pagination not working on template search.php
- Cutom wp_query for geolocation search, pagination not working
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- query_vars overriding WP_Query args
- Query with search and subscribers only output
- how can I override The Events Calendar query modifications?
- Search by post id in a specific page then auto-redirect to searched post
- Search for “2nd” also returns “22nd” in wp_query
- How to make search for posts using get method?
- Categorising search results based on Custom Fields
- Add filter post_where and passing post_type argument
- using pre_get_posts for search results not found
- Search posts missing a particular custom field
- How do I get my custom query to work with search results after the first page?
- Modify Search Query if original Query gave no results
- How can I override one post and make it display content for another post?
- Include post content of linked posts in search
- Replacing search results with custom external query
- Prevent author bio page from showing in search results
- How do I amend wp_query before it is run/executed?
- wp_query search not taking keywords with together for multiple words
- Wildcard search in WP Query
- Get a list of posts by specific category
- WordPress Custom Search Form Displaying Unexpected Results
- Search Page Returns Nothing
- queried_object using pre_get_posts gets notices and warning
- Utilising an existing page while using the “s” query parameter
- Redirect Search to Form When No Product Results Are Found
- How to properly use AND / OR in custom search
- How to avoid bypass of search bar rules?
- Hide products in uncategorized category from search results
- Issues with search after added meta_query