•

Why my WordPress sitemap stopped listing new posts

While going through this site’s SEO in October, I noticed new posts weren’t being picked up by Google as quickly as they should. The reason turned out to be the sitemap: it had quietly stopped updating three weeks earlier.

The symptoms

  • The post sitemap listed 47 URLs, but the site had 62 published posts.
  • Nothing published after 24 September appeared in it.
  • Adding a cache-busting query string to the sitemap URL made no difference, so it wasn’t my browser or the page cache.

What made it tricky

Nothing looked broken. The sitemap loaded, it was valid XML, and Search Console reported it as read successfully. The only way to spot the problem was to count.

How I tracked it down

First I compared the number of published posts with the number of URLs in the sitemap:

wp post list --post_type=post --post_status=publish --format=count
curl -s https://websiteadmin.co.uk/post-sitemap.xml | grep -c '<loc>'

Rank Math, the SEO plugin on this site, saves its generated sitemaps as files in wp-content/uploads/rank-math/. The newest file there was dated 24 September, which matched the last post that appeared.

Rank Math is meant to clear those files whenever a post is published. Every post since 24 September had been published by an AI writing plugin, and whatever route it uses to publish, the sitemap cache wasn’t being cleared.

The cause

Stale cached sitemap files that were never refreshed for posts published by another plugin.

The fix

Clearing the cache fixed it straight away. Saving any Rank Math setting does this, or from WP-CLI:

wp eval 'RankMathSitemapCache::invalidate_storage();'

To stop it happening again, I switched sitemap caching off in the theme. For a site with a few hundred URLs, building the sitemap on request is quick, so there’s no real cost:

add_filter( 'rank_math/sitemap/enable_caching', '__return_false' );

The sitemap now lists every published post, including ones published by the AI plugin.

How to stop it happening to you

  • If anything publishes posts for you, such as an AI writer, a scheduler or an import, check your sitemap afterwards.
  • Once a month, compare the number of URLs in your sitemap with the number of published posts.
  • In Search Console’s Sitemaps report, the number of discovered pages should rise as you publish. If it stalls, look at the sitemap.

Time to fix: under half an hour once I’d spotted it.