Skip to content

WT-1469: Add management commands for importing WordPress blog posts#1627

Draft
StuartMacKay wants to merge 2 commits into
mozmeao:mainfrom
StuartMacKay:wagtail-wordpress-import
Draft

WT-1469: Add management commands for importing WordPress blog posts#1627
StuartMacKay wants to merge 2 commits into
mozmeao:mainfrom
StuartMacKay:wagtail-wordpress-import

Conversation

@StuartMacKay

Copy link
Copy Markdown
Contributor

One-line summary

Import Wordpress blog posts, exported from blog.mozilla.org, into Wagtail CMS.

Significant changes and points to review

This pull request adds two management commands:

  1. import_wordpress_blog_posts, which parses the WordPress export XML into BlogArticlePage entries (topics, tags, authors, images, and content blocks).

  2. import_wordpress_redirects, which creates Redirect records from the CSV the import command produces.

Also adds an Author snippet model with a BlogArticlePage.author field and ?author= filtering on the blog index, plus tests for all of the above.

Issue / Bugzilla link

https://mozilla-hub.atlassian.net/browse/WT-1469

Testing

These two commands import the WordPress blog export into Wagtail. Test them locally against mozilla-blog-posts.xml.

IMPORTANT: If you want to test using Docker you will have to modify Dockerfile to copy the xml file so the management commands can access it. Insert the follwing starting at line 107

COPY ./mozilla-blog-posts.xml ./

Import the blog posts

python manage.py import_wordpress_blog_posts mozilla-blog-posts.xml --dry-run`

Confirms the file parses cleanly and shows what would be imported, without writing anything.

python manage.py import_wordpress_blog_posts mozilla-blog-posts.xml

Runs the import for real. Look for a final summary line like:

Done. 68 imported, 0 skipped, 0 failed.

Any failures are logged per-post to stderr and don't stop the rest of the import.

Verify in the Wagtail admin:

  • Under the Blog index page, confirm the new BlogArticlePages appear with the correct title, topic, tags, author, and hero image.
  • Open a couple of articles and check the body content renders (text, inline images, code blocks) and, for the two posts with old YouTube embeds, that the embed link renders as plain text.
  • Check Snippets → Authors and Snippets → Tags to confirm authors/topics/tags were created (not duplicated).

Re-run to check idempotency:

python manage.py import_wordpress_blog_posts mozilla-blog-posts.xml

Should report 0 imported, 68 skipped, 0 failed — no duplicate pages created.

Create redirects from the old WordPress URLs

The first command writes wordpress_redirects.csv (old permalink → new page). Use it to create Wagtail redirects:

python manage.py import_wordpress_redirects wordpress_redirects.csv --dry-run

Shows what redirects would be created.

python manage.py import_wordpress_redirects wordpress_redirects.csv

Creates the redirects for real.

Verify in the Wagtail admin:

  • Go to Settings → Redirects and confirm entries exist mapping old blog.mozilla.org/en/... paths to the new blog article pages.
  • Re-run the command again — it should report the redirects as already existing rather than duplicating them.

StuartMacKay and others added 2 commits July 20, 2026 15:04
Adds two management commands:

1. import_wordpress_blog_posts, which parses the WordPress export XML
   into BlogArticlePage entries (topics, tags, authors, images, and
   content blocks).

2. import_wordpress_redirects, which creates Redirect records from the
   CSV the import command produces.

Also adds an Author snippet model with a BlogArticlePage.author field
and ?author= filtering on the blog index, plus tests for all of the
above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants