Prevent Including Sitemaps with Zero Content
There are a variety of situations which create empty sitemaps that cause problems for the user.
If a sitemap returns zero content, it should automatically not be included.
Currently, these sitemaps are included and result in 404s and other problems (sometimes even referencing hidden or disabled taxonomies).
Whether this is the case of there being no posts on the blog (thus an empty posts sitemap) or a custom taxonomy being empty (as is sometimes the case when a plugin based system is deactivated but not deleted), having empty sitemaps not appear would reduce support ticket load and user headaches.
This may require a user interface annotation that lets them know that only sitemaps containing entries will be displayed in the sitemap_index.xml
(Moved from Premium #346 to Free)
Note to self — look at Jetpack's stuff as mentioned in original issue https://wordpress.org/support/topic/jetpack-putting-jetpack-portfolio-type-sitemapxmlin-sitemap?replies=7
So with more visibility of how this work after huge refactoring pass the situation is following.
For every sitemap there are two separate routines — the one that generates index links in root sitemap and the one that generates links for specific page of sitemap. Obviously the intent is for them to be in sync. The code already does its best to only generate meaningful index links.
However building index links is much lighter operation. We simply cannot afford to build every single sitemap page to check that everything in our index is reliably non–empty.
So, while the intent it for them to always be in sync, there is no generic solution to this. It will be improving the related logic case by case whenever something specific comes up.