Use `wp` filter to detect site map requests. Only invalidate main query and make sure $wp_query is set.
Use `pre_get_posts` but check for main query
Merge pull request #1216 from dannyvankooten/master

use `is_main_query` to prevent issues. Props @dannyvankooten