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()
.