How LUXCM Exports Media by Category
Category-Based Export — How to Automatically Include Only the Images and Media You Need
When I was building category-based exports, I spent far more time thinking about how to identify the media attached to a category than about selecting the category itself.
Choosing the posts is easy.
The real challenge is determining exactly which images those posts actually use.
Handle this casually and you end up with one of two failures: necessary images go missing and break the new site, or the entire media library comes along and bloats the files.
I encountered both failure modes myself, and I’ll use them as the basis for this explanation.
“The Featured Image Disappears” Is a Longstanding Problem with WordPress’s Standard Tools
Let’s start with the first failure: leaving out images that are actually needed. This isn’t a hypothetical concern.
Kellen Mace’s article describes the fact that WordPress’s built-in export/import tools “do not automatically bring featured images along when moving posts” as “silly and counterintuitive.”
To work around the problem, the article recommends installing and using a separate “Export Featured Images” plugin. Even that solution comes with a limitation: it works only when the post IDs on the source and destination sites are identical.
A response on The Events Calendar support forum explains exactly why this happens.
Featured images are not stored as files themselves. They are stored as post meta containing the ID of an image attachment.
But if you export only the posts and do not include the media attachments they reference, the destination site has no post with that ID.
And even when that ID is present, it may end up pointing to a different type of post. The support team makes clear that this is not a bug in a particular plugin, but a limitation of WordPress’s built-in import/export functionality.
Once I understood this structure, I identified two things that a category-based export absolutely has to handle.
First, it must find the images actually embedded in the content of the selected posts.
Second, it must separately find attachments assigned as featured images, even though they do not appear in the content itself.
These two types of media use different storage mechanisms—URL strings in the post content versus the _thumbnail_id post meta field—so a single piece of logic cannot reliably detect both.
That is why my logic splits into exactly these two paths. First, it scans the selected posts’ content (post_content) and identifies every media-library attachment URL that actually appears in the content.
This is the path used to catch images inserted directly into the content.
Then, for each post, it separately calls get_post_thumbnail_id() to identify the attachment ID assigned as the featured image.
This catches images linked to the post that do not appear in its content at all.
I combine the IDs found through both paths to create the list of attachments actually required for the export.
As The Events Calendar forum correctly pointed out, the problem of “the post referenced by the featured image not existing on the destination site” disappears if that post—the featured image attachment—is included in the export from the start.
Bringing Along the Entire Media Library Is Not the Answer Either
Another way to solve the problem would have been to export the entire media library every time.
In fact, many people who use WordPress’s built-in tools take this approach: because a partial selection does not bring media along at all, they export everything as a workaround.
But I decided that this was not a good answer either.
WP Engine’s guide to cleaning up the WordPress media library puts it this way: “It’s common to accumulate” files that are no longer necessary over time, which is why regular cleanups every month or two are recommended.
There is another source of waste as well. When you upload a single image, WordPress automatically creates multiple derivative sizes, while themes and plugins may generate even more versions, multiplying the amount of storage consumed.
The guide explains that accumulated media can “slow down your site, affect Core Web Vitals, and make media management itself more difficult.”
I built this reality directly into the design of category-based exports.
Telling someone who wants to move only a few posts from one category that they must export the entire media library as well is effectively asking them to move years’ worth of images from other categories, banners from long-deleted campaigns, and forgotten files uploaded for testing to the new site too.
That is why category mode does not search through the entire media library.
It identifies and includes only the attachments that the selected posts actually reference.
This stands in clear contrast to the “full” mode, which includes the entire library by default. Full mode assumes, “There is no way to know which images each post will use later, so bring everything.” Category mode works from the opposite assumption: “We already know exactly what the selected posts use, so bring only that.”
The Honest Limitation of This Approach
I would not claim that this logic is perfect.
The content scan works by checking whether an attachment’s URL string appears directly in the post content.
In other words, it assumes that the image address saved in the post content exactly matches the original address registered in the media library.
I know that images inserted through the WordPress editor often use the URL of a resized version rather than the original. Addressing this would require the actual rehosting and URL-rewriting functionality handled by the paid add-on, which is outside the scope of the free version.
The category-based export in this free version is designed solely to identify the metadata of the attachments used by those posts—the original URLs, post meta, and taxonomy information—and include it in the .wpmpx file. Downloading and transferring the actual image files is outside the scope of this free version, as I explained in the previous article.
Even so, these two detection paths—matching content URLs and explicitly checking featured images—reliably prevent the most common and visible failure identified in The Events Calendar forum: the post referenced by a featured image not existing at all on the destination site.
Because a featured image is a type of reference that a content scan can never detect, omitting this separate check would have caused the category-based export to reproduce exactly the problem Kellen Mace described.
To sum up the LUXCM approach
The problem I wanted to solve with category-based exports was straightforward:
“Include exactly—and without omissions—the images needed by the selected posts.”
WordPress’s standard tools have struggled with this problem for years because they do not properly account for the fact that featured images are stored as ID references rather than as posts themselves. The tools created as workarounds introduced another limitation: the post IDs must match those on the original site.
I addressed it with two independent detection paths—scanning the content and checking the featured image—without resorting to the blanket inclusion of the entire media library.
Include exactly what the selected content needs, without leaving anything out. That is the principle category-based exports are designed to uphold.