Automating a WordPress content audit works best as a two-layer system. WP-CLI handles the deterministic work: enumerating public URLs, querying the database for missing metadata, pulling every internal link out of post content, and checking whether each target resolves. An AI layer handles the interpretive work: clustering pages by topic, spotting intent mismatches, ranking which pages are worth updating, and drafting the fix list. The split matters because language models are unreliable at counting and querying, while SQL and HTTP checks are unreliable at judging whether a page is still useful to a reader.
This guide is written for technically curious beginners and intermediate practitioners who can run commands against a server or a local copy of a site. It describes a reproducible pipeline, the commands that make each stage work, and the points where automation quietly corrupts data or produces confident nonsense.
What a content audit actually has to answer
Most audit requests reduce to a small set of questions:
- Is every public URL accounted for, and does the sitemap match reality?
- Which pages are excluded from search, intentionally or accidentally?
- Which published posts are missing a meta description, an excerpt, or a meaningful title?
- Which internal links are broken or redirecting, and which posts contain them?
- Which pages are orphaned, stale, overlapping, or aimed at the wrong search intent?
WP-CLI answers the first four cheaply and repeatably. The fifth is where an AI layer earns its place, because it requires reading and comparing content rather than counting rows.
Prerequisites and safety rails
Before running anything, confirm the following:
- WP-CLI is installed and working on the target environment, with shell access over SSH or a local development copy. Run
wp --infoto confirm the binary, PHP version, and WordPress path. - You have a database backup and, ideally, a staging clone. Every stage below except the read-only queries should be rehearsed on staging first.
- You know which post meta keys your SEO plugin uses. This is the single most common source of wasted audit work. The key that stores a hand-written description differs between Yoast, Rank Math, and SEOPress, and a query against the wrong key returns a clean-looking site that is not clean.
- You have decided where page content is allowed to go. Sending post bodies to a hosted model is a data-transfer decision, not a technical default. If the site contains client or personal data, a locally hosted model keeps the content on your own hardware.
Stage 1 — Build a complete URL inventory
Start with the content types that produce public URLs. A CSV export is the most useful format because it diffs cleanly against a sitemap and pastes easily into a spreadsheet or a model prompt.
wp post list
--post_type=post,page
--post_status=publish
--fields=ID,post_title,post_name,post_type,post_modified
--format=csv > inventory-posts.csvRepeat the same pattern for custom post types, then add terms and author archives, which are public URLs on most sites but are frequently missing from a manual inventory:
wp term list category --fields=term_id,name,slug,count --format=csv > inventory-categories.csv
wp user list --fields=ID,user_nicename,display_name --format=csv > inventory-authors.csvThen compare the inventory against what the site actually advertises. WP-CLI has no core sitemap command, so the practical approach is to inspect the sitemap system with wp eval: check whether WordPress core sitemaps are enabled, which providers and subtypes are registered, and how many entries each one produces. The exact API calls depend on your WordPress version, so verify the function exists before relying on it:
wp eval 'var_dump( function_exists( "wp_sitemaps_get_server" ) );'If a third-party SEO plugin supplies the sitemap instead, fetch the sitemap index over HTTP and diff the URL set against inventory-posts.csv. URLs present in the inventory but absent from the sitemap are the first concrete finding of the audit.
Stage 2 — Query the database for metadata gaps
Missing metadata is a database question, and wp db query answers it in one pass. The example below targets the Yoast description key; substitute the key your plugin actually stores, and confirm it by inspecting a known-good post first.
wp db query "SELECT p.ID, p.post_title, p.post_type
FROM wp_posts p
LEFT JOIN wp_postmeta m
ON p.ID = m.post_id
AND m.meta_key = '_yoast_wpseo_metadesc'
WHERE p.post_status = 'publish'
AND p.post_type IN ('post','page')
AND (m.meta_value IS NULL OR m.meta_value = '');"The same pattern finds posts with an empty excerpt, which many themes use as the archive summary, and posts marked noindex. Noindex storage differs by plugin: some store a simple flag, others a serialized array of robots directives. Query the raw meta value, then confirm the result against the live page.
That confirmation step is not optional. A database row describes stored state; it does not describe what a crawler receives after a plugin, a filter, or a caching layer has modified the output. The documented recipe for listing noindexed content explicitly pairs the database query with a check of live meta tags and response headers for exactly this reason.
Stage 3 — Find broken and redirecting internal links
Internal link checking is a three-step pipeline: extract, deduplicate, verify.
- Extract. Dump post content for published posts and pages with
wp db query, then pull every internalhrefout of the HTML. - Deduplicate. Build a unique list of internal targets. Checking the same URL once instead of once per mention is the difference between a two-minute job and a two-hour one.
- Verify. Request each unique target once and record the status code.
curl -o /dev/null -s -w '%{http_code} %{redirect_url}n' "$url"A 200 is healthy. A 301 or 302 means the link works but costs a redirect hop. A 404 or 410 is broken. Map each unique target back to the post IDs that reference it, so the output is a fix list rather than a list of URLs.
Stage 4 — Add the AI triage layer
By this point you have structured data: an inventory CSV, a metadata gap list, and a link report. This is the right input for a model, because the facts are already established and the model is only being asked to interpret them.
A workable prompt shape asks for one record per page with a fixed schema, for example a primary topic, a content type, a freshness risk, and a recommended action. Batching twenty to fifty rows per request keeps responses coherent and makes failures easy to isolate. Requesting JSON output and validating it before use prevents a model’s formatting drift from breaking a downstream script.
Two design choices matter more than prompt wording. First, keep the model away from anything that must be exact — counts, IDs, status codes, and URLs should pass through unchanged from the WP-CLI output. Second, treat every model recommendation as a proposal requiring human review, especially anything that would change a published page, a title, or a canonical URL.
If the site’s content cannot leave your infrastructure, the same pipeline runs against a locally hosted model. The extraction and query stages are identical; only the inference endpoint changes, and the tradeoff is usually throughput and reasoning quality rather than feasibility.
Stage 5 — Remote audits over MCP when there is no SSH
Not every site gives you a shell. A project published as OBSTechnologies/wp-mcp-audit takes a different route: a WordPress plugin is installed on the client site, and an MCP (Model Context Protocol) server running locally connects an AI client to that site over the WordPress REST API using application passwords. The repository describes the workflow as running checks, reading plugin and theme source, querying the database, and applying fixes conversationally, with no SSH required.
The documented setup is three steps: upload and activate the plugin, which the README states requires PHP 7.4+ and WordPress 5.8+ and registers an “Auditor” role with custom capabilities; create an application password under Users → Profile; and configure a local sites.json file with the site URL, username, application password, and optional feature flags such as WooCommerce. The MCP server is then registered in an AI client’s configuration.
Two cautions apply. The project is small and new — the repository shows zero stars and one fork at the time of writing — so review the plugin source and test on a staging site before granting it write access to production. And an MCP server that can apply fixes is a different risk category from a read-only audit script: scope the application password’s user to the minimum role that works, and treat every automated write as a change requiring review.
Acting on the findings without breaking the site
The audit is only useful if the fixes land safely. The highest-risk operation in this whole workflow is a bulk URL change. A domain change must be handled with a dry run first, PHP-based serialization handling, and the guid column skipped, because GUIDs are identifiers rather than links and rewriting them can break feeds and references:
wp search-replace 'https://old.example.com' 'https://new.example.com'
--precise --skip-columns=guid --dry-runRemove --dry-run only after reviewing the reported row counts, and re-run the audit afterwards to confirm the change took effect. For slug changes, core’s _wp_old_slug handling covers posts but not pages, so a redirect is the reliable option; if the change is scheduled, remember that WP-Cron runs in UTC. When a sitemap or custom URL starts returning 404, find the matching rule before flushing:
wp rewrite list --match="/sitemap"
wp rewrite flush --hardLimits, tradeoffs and how to verify the result
Four limitations are worth stating plainly. Database queries describe stored state, not rendered output, so noindex and canonical findings need live confirmation. Meta keys are plugin-specific and change between major versions, so a query that worked last year may silently return nothing. AI triage is probabilistic: it is good at clustering and prioritisation and unreliable at anything requiring exactness, which is why the deterministic stages come first. And sending content to a hosted model is a disclosure decision that a local model avoids at the cost of your own hardware and time.
Verification is straightforward: re-run the same commands after the fixes and diff the outputs. A successful audit is one where the inventory matches the sitemap, the metadata gap query returns fewer rows, the link report contains no 404s, and every AI-recommended change has been reviewed by a person before publication.
A sensible next step
If you are starting from scratch, do not build the whole pipeline at once. Run Stage 1 and Stage 2 read-only against a staging copy today — they take minutes, require no writes, and usually surface enough findings to justify the rest. Add the link checker next, then introduce the AI triage layer once you have clean structured input for it.
Readers working through this on their own sites are welcome to share their environment, the commands they ran, and any errors in the community discussion — the plugin-specific meta keys and rewrite-rule edge cases are exactly the kind of detail that is worth comparing across setups.
FAQ
Does WP-CLI have a built-in sitemap command?
No. WP-CLI has no core sitemap command, so sitemap inspection is normally done with wp eval to check whether core sitemaps are enabled and which providers and subtypes exist, or by fetching the sitemap index over HTTP and comparing it with a URL inventory.
Can an AI model replace the audit queries?
It should not. Keep enumeration, database queries and HTTP status checks deterministic, and use the model only for interpretation tasks such as clustering pages by topic, spotting intent overlap and ranking which pages to update first.
Why does a noindex query need a live check?
A database row shows stored state, not what a crawler receives. Plugins, filters and caching layers can change the emitted meta tags and headers, so the database result should be confirmed against the live page.
Is a domain change safe with wp search-replace?
It is safe when run carefully: back up first, run with --dry-run to review affected rows, use --precise so replacement is handled in PHP for serialized data, and skip the guid column because GUIDs are identifiers rather than links.