$query->query_var[‘post_type’] not set for pages
To clear up some confusion in previous answers, pre_get_posts isn’t a filter so you don’t need to return anything. Your only problem that I see is the if: if ( !is_search() && !in_array( get_post_type(), $post_types ) ) return; Basically get_post_type() is going to return false during pre_get_posts because the global $post hasn’t been set yet … Read more