is_main_query will probably be what you're looking for. It's only true for the main query that WP will execute to find the post(s) that the request is asking for, but not for consecutive queries (as a custom query in your header). I've edited my answer to include it.
↧