Make WordPress Core

Opened 12 years ago

Last modified 2 weeks ago

#17379 reviewing defect (bug)

Filtered exports drop attachments and featured images

Reported by: billseymour's profile billseymour Owned by: chriscct7's profile chriscct7
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Export Keywords: has-patch has-unit-tests has-testing-info
Focuses: Cc:


When using Tools>Export, targeting a specific author, the resulting XML file does not contain a reference/link to any Featured Image (thumbnail) associated with these posts.

On the other hand, Tools>Export "all content" (including all authors) produces an XML file that does contain reference/link to Featured Image.

Request: Have Tools>Export "specific author" generate the same metadata as the "all content" export, so that Export "specific author" will also include metadata reference to the Featured Image.

Many people (including myself) use "specific author" as a way to export some, but not all, posts. Full metadata would really help. Thanks.

Attachments (2)

export_attachments_for_cpt.diff (1.3 KB) - added by jghazally 11 years ago.
Include attachments for specific post_types
export-with-attachments.diff (1.8 KB) - added by Ganon 9 years ago.
Export with attachments and thumbnails

Download all attachments as: .zip

Change History (40)

#1 @duck_
12 years ago

The problem isn't missing meta data (see <wp:meta_key>_thumbnail_id</wp:meta_key>). Rather the fact that no attachments are exported/imported so the reference doesn't mean anything in the imported install.

#2 @jane
12 years ago

  • Summary changed from Export Posts by Author- Featured Image reference to Export Posts by Author needs Featured Image reference

#3 @duck_
12 years ago

  • Component changed from General to Export
  • Summary changed from Export Posts by Author needs Featured Image reference to Filtered exports drop attachments and featured images
  • Version set to 3.0

Marked #19591 as dupe. Definitely present in 3.0, and I'm pretty sure it was present earlier than that but I haven't checked.

Related: #19307

#4 @rcain
12 years ago

thought it might be helpful to suggest a very simple solution to this:

can we not have an 'export attachments only' option (alongside 'export posts only', etc)?

i've just implemented similar in the old advanced-export-forwp-wpmu plugin here : - which i believe is pretty similar code.

since big exports generally have to be done in smaller batches anyway, exporting attachments separately seems logical.

on the flip-side, there still appear to be some issues with the wordpress-importer plugin (eg:, but this would seem a practical step in the right direction.

#5 @Ipstenu
11 years ago

  • Cc ipstenu@… added

#6 @johnbillion
11 years ago

  • Cc johnbillion added

#7 @jtsternberg
11 years ago

  • Cc justin@… added

#8 @JarretC
11 years ago

  • Cc jarretcade@… added

11 years ago

Include attachments for specific post_types

#9 @jghazally
11 years ago

Hi I just came across this problem when trying to import a CPT, the featured images (and other attachments) are not included in the xml file. I have attached a patch above to fix my issue which is fairly basic and can probably be improved. It can also be made to utilize a checkbox as per @rcain 's suggestion.
Hope this helps core out.


#10 @batmoo
11 years ago

  • Cc batmoo@… added

#11 @smub
11 years ago

Just ran into this issue. This also breaks conditionals like has_post_thumbnail() ... Just exported about 24 posts from a site to test on local dev environment (building a new theme). Put up some dummy thumbnails on few articles. Then added a custom field for image URLs (just to simulate posts from pre WP 2.9)... Was running a conditional and it wasn't working. Spend all the time just to realize it was because an attachment ID was saved. So while it doesn't display a thumbnail that is attached, it stores an ID in the database thus causing the conditional to return TRUE when it is not.

#12 @travisnorthcutt
11 years ago

  • Cc travis@… added

A big fat +1 from me on this. My use case was exporting/importing a custom post type with associated featured images. The code posted by @jghazally worked *perfectly* for me.

#13 @wingfingerbill
11 years ago

  • Cc wingfingerbill added

#14 @jghazally
11 years ago

If someone wants to give me an idea of what sort of UI / form elements we want to use, and a hand getting started on Unit Testing this would love to help...


#15 @batmoo
11 years ago

export_attachments_for_cpt.diff works pretty nicely. Would be nice to get this into 3.5.

#16 @axwax
11 years ago

+1 on getting that patch by @jghazally into 3.5

Version 0, edited 11 years ago by axwax (next)

#17 @creativeslice
11 years ago

  • Keywords has-patch added

We've been able to get this to work with a hack to the Advanced Export plugin, however it's quite brittle and only allows you to filter by date and author, not category. It would be great to have this fixed in core so exporting a range of posts works without dropping images.

#18 @lachlanj
11 years ago

  • Cc lachlan@… added

#19 @dlocc
11 years ago

Thanks to the export_attachments_for_cpt.diff for working great! I'm happy I found this... saved me bunches of time. Why wasn't this included in 3.5? It should definitely be rolled out.

#20 @jghazally
11 years ago

@dlocc the export system is getting overhauled and a new API is being developed see #22435

#21 @betzster
10 years ago

  • Cc j@… added

#22 @nacin
10 years ago

  • Milestone changed from Awaiting Review to 3.7
  • Type changed from feature request to enhancement

#23 @nacin
10 years ago

  • Type changed from enhancement to defect (bug)

Really, this is a bug.

The patch seems OK, but I'm not sure about it. A few issues:

  • How well will that query work when there are a lot of post IDs? It's possible that you could be exporting tens of thousands of post IDs of a single type. The IN would get too long at some point.
  • Unless my memory is failing me, featured images aren't necessarily attached to posts. We'd need to check each post's metadata and append the post to the posts to export if it is missing.

#24 @nacin
10 years ago

  • Milestone changed from 3.7 to 3.8

#25 @nacin
10 years ago

  • Milestone changed from 3.8 to Future Release

Some concerns still.

#26 @wonderboymusic
9 years ago

  • Keywords needs-patch added; has-patch removed

Featured images are always related by a post meta entry, not necessarily by post_parent. Needs a new patch.

9 years ago

Export with attachments and thumbnails

#27 @Ganon
9 years ago

I've attached a patch that should comply with your requirements, gets the thumbnail from the postmeta and doesn't creates long queries.

#28 @SergeyBiryukov
9 years ago

  • Keywords has-patch added; needs-patch removed

#29 @Ganon
9 years ago

Hmm, could we have this scheduled for the next release?

#30 @hlashbrooke
9 years ago

Just to note - I made a few significant improvements to the export function in #27048 - I wasn't directly intending to fix this issue with attachments, but it was indirectly fixed in that patch.

#31 @chriscct7
8 years ago

  • Owner set to chriscct7
  • Status changed from new to reviewing

This ticket was mentioned in PR #4245 on WordPress/wordpress-develop by nate-allen.

7 months ago

  • Keywords has-unit-tests added

This pull request fixes an issue where attachments are not included when exporting posts, unless you choose the "all" option.

A unit test is also included.

Trac ticket: 17379

#33 @nateallen
7 months ago

  • Keywords has-testing-info added

I cleaned up the code a bit and adding a new unit test. I'm hopeful we can finally merge this fix into WordPress core. Given that the bug has caused frustration for WordPress users for more than a decade, I'm eager to see it resolved at last!

To test this patch:

  1. Create a post and add a featured image
  2. Go to Tools > Export
  3. Select the Posts option
  4. Choose an author
  5. Click "Download Export File"

The export file should contain your post and the attachment. Without the patch, you should only see the post.

#34 @fischfood
6 months ago

Test Report

This report validates that the indicated patch addresses the issue.
Patch tested:
OS: macOS 12.4
PHP: 8.0.16
WordPress: 6.1.1
Browser: Brave 1.48.164, Chrome 111.0.5563.64
Theme: Twenty Twenty-Two


  • Updated wp-admin/includes/export.php on a live website for public image access
  • Added a post to the live site with a featured image, and an image within the content
  • On that site, I ran two exports, one for all posts with "Posts", and one for all posts by a specific author
  • On a clean local site, I ran an import for each xml file, checking off the "Download and import file attachments" option, sacking the post and images in between the tests


  • On both imports, a post was created with the featured image as well as the image within the content. Both images were uploaded into the Media Gallery.
Last edited 6 months ago by fischfood (previous) (diff)

@hifidesign commented on PR #4245:

3 weeks ago

If support for PHP versions < v7 has been dropped, why is this holding up the merge of a patch for a 12 year old Trac ticket?

#36 @hifidesign
3 weeks ago

@nateallen you're awesome!

Seems like closing this 12 year old Trac ticket would be a win. Now that support for PHP versions below v7 has been dropped, can anyone clarify why unit test requirements for PHP 5.6 holding up the merge for this patch?

@nateallen commented on PR #4245:

2 weeks ago

@electricbrick Should I close this pull request and open a new one? That would trigger a new checks on the code that don't include PHP 5.6.

@hifidesign commented on PR #4245:

2 weeks ago

@nate-allen Good question... By the way, my reply was meant more for maintainers to see activity on the ticket, and not shade @ you.

is a new PR against the rules? Because maybe it would work — are there potentially unforeseen consequences though? An alternative is someone could show up at the Make Slack contributors stand-up and advocate for it. I don't know if that's still held on Wednesdays.

Note: See TracTickets for help on using tickets.