We handle querying for the sitemap post on render (i.e after the template_include hook) which means that WordPress' main query has already run, which is a waste since that query and it's results are never used.
We should probably replace the query to look up the post for single sitemaps and kill it for the root sitemap.
Hi @mjangda What are your thoughts on using the posts_pre_query filter that was added in 4.6 to "kill" the main query. We'll still have the php processing of WP_Query occur but there won't be a db hit. I've implemented the filter in my forked branch https://github.com/mdbitz/msm-sitemap/blob/fix/102/msm-sitemap.php However I'm having issues getting a proper unit test setup. going to post a message in slack to see if someone has tips.
I thought I could use go_to in the phpunit test to confirm that $wp_query was returning posts on the main page then hit sitemap.xml and confirm it returned empty but that doesn't seem to be the case.
Mo, spoke with Dennis Snell and got some great feedback on setting up appropriate unit tests for the filter. Let me know your thoughts on if you feel posts_pre_query is the proper way to resolve the main query load and if so I'll get a pull request setup.