If your All in One SEO sitemap is not working, check four things in this order: a physical sitemap.xml file sitting in the document root, a page cache or CDN serving a stale copy, rewrite rules that were never flushed, and the sitemap module or a post type switched off inside AIOSEO itself. AIOSEO builds /sitemap.xml on the fly through WordPress rewrite rules, so anything that answers that URL before WordPress does — a real file on disk, an edge cache — wins silently, and there is no error message anywhere to find. The second family of AIOSEO problems is older and quieter: half-finished upgrades from All in One SEO Pack 2.x and 3.x that leave _aioseop_* post meta in wp_postmeta while the front end reads the newer wp_aioseo_posts table. This page works the whole diagnostic order with WP-CLI and curl, from the request path down to the tables.
What you’ll accomplish
- A
/sitemap.xmlthat answers200with an XML content type, is generated by AIOSEO rather than by a leftover file, and changes when you publish. - One clear answer to “who owns this URL”: no physical sitemap on disk, no stale edge copy, rewrite rules flushed and proven.
- A single JSON-LD graph per page instead of AIOSEO’s graph competing with the theme’s or another plugin’s.
- A
wp_aioseo_poststable whose row count tracks published posts, with legacy_aioseop_*meta accounted for rather than quietly ignored. - A size check on the redirect and Link Assistant tables, so the SEO plugin is not the largest object in your database.
Prerequisites
- WordPress 5.9 or newer on PHP 7.4 or newer, running AIOSEO 4.x. Everything below assumes the 4.x branch. If
wp plugin get all-in-one-seo-pack --field=versionstill reports a 3.x number, the migration section is your entire article. - Shell access with WP-CLI and
curl. Much of this is visible in wp-admin, but you cannot see response headers or the filesystem from there, and those account for two of the four sitemap failures. - Database access good enough for
wp db query, plus a backup you have actually restored at least once. Two steps below delete rows. - The default table prefix
wp_is assumed throughout. If your install uses a different prefix, substitute it everywherewp_aioseo_appears. - Permission to purge whatever sits in front of PHP: LiteSpeed Cache, WP Rocket, Varnish, Cloudflare, or several of them stacked.
jqis convenient because AIOSEO storesaioseo_optionsas a JSON string, but nothing here requires it.
How it works
WordPress has no static sitemap. A request for /sitemap.xml is a normal front-end request that gets rewritten into a query, and the plugin that claimed the rule renders XML in response. That single fact explains most of the reports in this article: five separate systems get a chance to answer before AIOSEO does, and four of them can answer wrongly without logging anything.
Read the chain from the top. The CDN or page cache can hold XML for far longer than you expect, because caching layers often treat .xml as a static asset and give it a long TTL. Below that, Apache or nginx will serve a real file if one exists — and a real sitemap.xml does exist on a surprising number of sites, left behind by Google XML Sitemaps, by an old static-sitemap export, or by AIOSEO’s own static sitemap option from a previous configuration. PHP never runs in that case. Below that sit the rewrite rules: AIOSEO registers them on activation, and if wp_options lost rewrite_rules or another plugin rebuilt them without AIOSEO loaded, the URL simply 404s. Only at the bottom does the AIOSEO sitemap module get to build anything, and it reads from wp_aioseo_posts.
That table is also where the second problem lives. AIOSEO 4.x moved per-post SEO data out of wp_postmeta and into dedicated tables. The upgrade copies data across in Action Scheduler batches, which is the right design for a site with 80,000 posts and the wrong design for a host that kills long-running WP-Cron requests. When the batches stop halfway, nothing breaks loudly. Posts that got a row keep their titles; posts that did not fall back to the site-wide template. The legacy meta is still sitting in wp_postmeta, so a quick look suggests nothing was lost.
Step-by-step
-
Establish what actually answers the sitemap URL. Headers first, body second:
curl -sI https://example.com/sitemap.xmlHTTP/2 200 content-type: application/xml; charset=UTF-8 x-robots-tag: noindex cf-cache-status: HITA
content-typeoftext/htmlmeans WordPress served a page, not a sitemap. A404points at rewrite rules.cf-cache-status: HIT,x-litespeed-cache: hit, or anageheader in the hundreds of thousands means you are reading a cached copy and every conclusion you draw from the body is about the past. -
Rule out a physical file before touching any setting. This is the top cause and the fastest to check. From the document root:
ls -la sitemap.xml sitemap_index.xml 2>/dev/null find . -maxdepth 1 -name 'sitemap*.xml' -o -maxdepth 1 -name 'sitemap*.xml.gz'No output at all is the healthy result. If a file is listed, the web server has been serving it and AIOSEO has never been consulted. Rename it rather than deleting it —
mv sitemap.xml sitemap.xml.disabled— then re-run thecurl -sIfrom step 1 and confirm the response changed. -
Flush rewrite rules and confirm the sitemap rule exists. A hard flush rewrites
.htaccesson Apache, so take a copy first:wp rewrite flush --hard wp rewrite list --format=csv | grep -i sitemapRewrite rules flushed. sitemap\.xml$,index.php?aiosp_sitemap_path=root,rootThe exact query string varies by AIOSEO version; what matters is that a rule matching
sitemapexists at all. Ifwp rewrite listreturns nothing for sitemap, deactivate and reactivate AIOSEO so it re-registers its rules, then flush again. -
Purge every cache in front of the URL, then re-request it. Purge the page cache from its own plugin or CLI, purge the CDN, and verify with a cache-busting query string, which most edges pass straight through:
curl -s "https://example.com/sitemap.xml?nocache=$(date +%s)" | head -20<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="https://example.com/default.xsl"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap><loc>https://example.com/post-sitemap.xml</loc></sitemap> <sitemap><loc>https://example.com/page-sitemap.xml</loc></sitemap>If the fresh copy is correct and the cached one is not, your problem was never AIOSEO. Add a cache rule that excludes
sitemapURLs, or shorten the TTL for XML. -
Check the sitemap settings that silently drop content. AIOSEO keeps its configuration in one option, stored as JSON:
wp option get aioseo_options | jq '.sitemap.general'Two values matter. The enable flag decides whether the module answers at all — if the module is off, WordPress core’s own
/wp-sitemap.xmlmay be answering instead, which is a different sitemap with different contents. The links-per-page value controls pagination: with the default of 1,000 URLs per file, a site with 40,000 posts produces 40 child sitemaps, and a submission of only the index in Search Console is correct and normal. Then confirm which post types are included, because an excluded custom post type is the usual reason a sitemap looks half the size it should be. Set both in AIOSEO → Sitemaps → General Sitemap rather than editing the option by hand; the JSON is nested and easy to corrupt. -
Compare the sitemap URL count against reality. Count what the XML lists, then count what the database publishes:
curl -s https://example.com/post-sitemap.xml | grep -c '<loc>' wp db query "SELECT post_type, COUNT(*) FROM wp_posts WHERE post_status='publish' AND post_type NOT IN ('revision','nav_menu_item','attachment') GROUP BY post_type"The two should agree within the number of posts you have deliberately set to noindex. A large gap in either direction is the cue to look at the migration, which is step 7.
-
Establish how far the 4.x migration actually got. The diagram below is the state most inherited sites are in:
Three counts tell you where you stand:
wp db query "SHOW TABLES LIKE 'wp_aioseo_%'" wp db query "SELECT COUNT(*) AS rows_in_new_table FROM wp_aioseo_posts" wp db query "SELECT COUNT(DISTINCT post_id) AS posts_with_legacy_meta FROM wp_postmeta WHERE meta_key LIKE '_aioseop_%'"+--------------------+ | rows_in_new_table | +--------------------+ | 1204 | +--------------------+ +-------------------------+ | posts_with_legacy_meta | +-------------------------+ | 3891 | +-------------------------+A legacy count far above the new-table count is a stalled migration. Legacy meta on its own is not a problem — the migration copies rather than moves, so those rows are expected to survive a clean run. The signal is the ratio.
-
Restart a stalled migration. AIOSEO queues its upgrade work through Action Scheduler, so look there before assuming the plugin is broken:
wp db query "SELECT hook, status, COUNT(*) FROM wp_actionscheduler_actions WHERE hook LIKE '%aioseo%' GROUP BY hook, status"Pending rows that never move to
completemean the queue is not running — usually WP-Cron disabled without a replacement system cron, or a host that kills the loopback request. Fix the queue first by giving the site a real cron entry that callswp cron event run --due-now, then deactivate and reactivate AIOSEO so it re-enters its upgrade routine and re-queues the remaining batches. Re-run the counts from step 7 after an hour; the new-table count should be climbing. -
Find and remove orphan sitemap entries. When posts are deleted directly in SQL, or by an import tool that bypasses WordPress hooks, their
wp_aioseo_postsrows survive:wp db query "SELECT COUNT(*) AS orphans FROM wp_aioseo_posts a LEFT JOIN wp_posts p ON p.ID = a.post_id WHERE p.ID IS NULL"With a backup in hand, delete them:
wp db query "DELETE a FROM wp_aioseo_posts a LEFT JOIN wp_posts p ON p.ID = a.post_id WHERE p.ID IS NULL"Rows for posts that still exist but were switched to noindex are a different case: those belong in the table, they just should not be in the XML. Re-saving the post rewrites the row correctly.
-
Count the JSON-LD blocks on a real page. AIOSEO emits one
@graph; a block theme or a second plugin emitting its own is the standard cause of duplicate-entity warnings in the Rich Results Test:curl -s https://example.com/ | grep -c 'application/ld+json' curl -s https://example.com/ | grep -o '"@type":"[A-Za-z]*"' | sort | uniq -c | sort -rn2 2 "@type":"Organization" 1 "@type":"WebSite" 1 "@type":"BreadcrumbList"A count above
1means two sources are describing your site. Turn off the one that is not your SEO plugin — usually a theme option named “schema” or “structured data” — and keep AIOSEO as the single emitter. WordPress structured data covers which types are still worth emitting. -
Size the optional module tables. The Redirects and Link Assistant modules write a row per event, and on a busy site they outgrow everything else:
wp db query "SELECT table_name, ROUND((data_length+index_length)/1024/1024,1) AS mb, table_rows FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name LIKE '%aioseo%' ORDER BY mb DESC"If
wp_aioseo_redirects_404_logsor the Link Assistant tables are in the hundreds of megabytes, shorten the log retention window in the module’s own settings, or turn the 404 log off entirely. It is a diagnostic aid, not a feature your visitors benefit from.
Validate it works
Run all four checks in one pass. Every line should be explainable:
curl -sI "https://example.com/sitemap.xml?v=$(date +%s)" | head -3
curl -s https://example.com/post-sitemap.xml | grep -c '<loc>'
curl -s https://example.com/ | grep -c 'application/ld+json'
wp db query "SELECT (SELECT COUNT(*) FROM wp_aioseo_posts) AS aioseo_rows, (SELECT COUNT(*) FROM wp_posts WHERE post_status='publish' AND post_type IN ('post','page')) AS published"
HTTP/2 200
content-type: application/xml; charset=UTF-8
1204
1
+-------------+-----------+
| aioseo_rows | published |
+-------------+-----------+
| 1204 | 1198 |
+-------------+-----------+
aioseo_rows slightly above published is normal — drafts and scheduled posts get rows too. Far below is a migration that has not finished. Then publish a throwaway post, wait a minute, request the child sitemap with a fresh query string, and confirm the new URL appears. That single test proves the whole chain: the rule fires, the module builds, the table is current, and no cache is in the way.
Troubleshooting
The sitemap is correct over curl but wrong in a browser. Your browser is holding its own copy, or you are hitting a different edge node. Re-check with a cache-busting query string in the browser too, and compare the cf-ray or equivalent header between the two requests.
Search Console reports “Couldn’t fetch” on a sitemap that loads fine for you. Check for a firewall or bot-management rule blocking Googlebot’s user agent, and check the x-robots-tag header — some security plugins add noindex to every XML response, which does not stop the fetch but does confuse the report. Verify the submitted URL is the index, not a child sitemap you submitted years ago and later renamed. Search Console setup for WordPress covers the property side.
Two sitemaps exist: /sitemap.xml and /wp-sitemap.xml. WordPress core has shipped its own sitemap since 5.5. AIOSEO normally disables it, but if the AIOSEO module is off, or a robots.txt still advertises the core URL, both end up live and Google finds both. Submit one and only one.
Titles changed in the AIOSEO editor do not appear on the front end. The value went into wp_aioseo_posts and something downstream is still serving the old HTML — an object cache holding the row, a page cache holding the rendered page, or a second SEO plugin winning the wp_head priority. Confirm with wp db query "SELECT title FROM wp_aioseo_posts WHERE post_id=123" and compare against what curl returns for that URL.
The migration finishes but old titles come back on the next save. A legacy _aioseop_title value is being re-applied by a leftover snippet or an old importer still hooked into save_post. Search the codebase for _aioseop_ with grep -rn '_aioseop_' wp-content/ --include='*.php' before blaming the plugin.
When this is the wrong approach
If more than one SEO plugin is active, stop here and resolve that first — every diagnosis above becomes ambiguous when two plugins claim the same rewrite rule and the same wp_head output. Sitemap conflicts between multiple plugins is the right starting point.
If you are on a managed host that generates sitemaps at the platform level, or behind a reverse proxy you do not control, the filesystem and rewrite checks here will not reflect what visitors receive. Ask the host what answers /sitemap.xml before changing anything in WordPress.
And if the real complaint is that pages are not being indexed, a working sitemap is a small part of the answer. Sitemaps help discovery; they do not persuade Google to index thin or duplicated pages. Fix the sitemap because a broken one is a real obstacle, then look at the content.
The plugin’s own reference for module settings is at aioseo.com/docs/, and the WP-CLI commands used above are documented at developer.wordpress.org/cli/commands/.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.