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
- Search custom taxonomy term by name
- Hook/action after WP_Query gets posts to query custom tables for post-related meta
- Overriding The Loop with filter or hook
- Pagination not working for Custom search form & custom result template
- How to support multiple search terms query within one process?
- 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?
- 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]
- 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’s “request” SQL Query
- How do I search inside specific taxonomies in WordPress
- Modifying the Search Results
- Search Posts with Custom Fields as query
- Complex date range with WP_Query and BETWEEN
- 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?
- How to use filter hook “the_posts” with a function that refers to $this?
- showing all search result in one template
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- WP_Query Not Recognizing Taxonomy Parameter in Custom Search
- Custom Search Not Consistent with Results
- Editing the default wordpress search
- Multiple Search Terms WP_Query
- Set global $wp_query/$post variable for dynamic page generation
- WP Query Args – Title or Taxonomy Value
- WordPress pagination not working on template search.php
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- query_vars overriding WP_Query args
- 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 can I override one post and make it display content for another post?
- Replacing search results with custom external query
- wp_query search not taking keywords with together for multiple words
- Wildcard search in WP Query
- Get a list of posts by specific category
- Search Page Returns Nothing
- queried_object using pre_get_posts gets notices and warning
- Redirect Search to Form When No Product Results Are Found
- Issues with search after added meta_query
- Sorting search results with custom dropdown
- wp_query show all values
- change posts_orderby of the callback wp_query?
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- Search.php – return number of results but cannot loop through
- How to filter a static post page with ajax and $wp_query
- Searching not only by post name but also category
- $wp_query->found_posts not returning correct value
- How to search by slug and old slug in single API
- WordPress search WP_Query to cover multiple post types and their custom fields?
- How to prevent WP_Query from filtering on ‘s’ but keep ‘s’ for other purposes?
- Block internal search queries with pre_get_posts and regex rules
- Add dynamic search to paginated WP_Query
- How to make the WP query search for the “s” arg in other places too
- Search Exact on WordPress – Relevannsi Solution Not Working
- Pagination repeating posts on search results
- I have problems with the search query using multiple post types
- Categories In English version showing not canonical URL, instead shows query search result
- Filter admin ajax data by url query
- Display the search results like the original pages
- How to use jQuery validation to set the search bar to accept only a specific input?
- Display Search Results by tag_ID in my search.php
- How to debug none working search query?
- Search with WP_Query, but ignore href URLs in anchor tags?
- Limit default Search query to post_title
- Logging search queries for logged-in users
- How to show terms from another taxonomy
- Search Field that allows options of “Match any keyword” or “Match all keywords”
- Order & Orderby clause not working with custom query
- A very strange problem with search query
- Rewrite rule pagination on different url levels
- How to make the default WordPress search return borader results
- WordPress WP_Query offset parameter not working with search parameter
- WordPress WP_Query Array Custom search via taxonomies
- Search Query that Includes Custom Table
- Manipulating a query
- Query posts by custom fields
- Searching in specific custom post type
- Search (Custom Form, Custom Search Result)
- Why does WP_Query not search for two ‘meta_query’ keys separated with OR?
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- Search query alteration not working for meta values
- Advanced Search – Is this possible?
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- AJAX multiple search boxes not merging with array merge