0

I've got about 300 images in the media library of one WordPress install.

I need to move these to the media library of a completely different WP site. This is NOT a full-site migration to a new URL. I only need to move 300 images.

When I tried to copy the images from site #1 into the uploads folder of site #2, they weren't recognized by the media library, obviously because metadata is involved.

I tried using a plugin called 'Add From Server' - but this didn't read the thumbnails from site #1 properly... it uploaded them as individual images, not very smart.

I also tried to initiate some kind of transfer from the MySQL command line, but the data is coming from two different tables, wp_posts and wp_post_meta, and I don't fully understand the structure of these.

So is there any way to do this, aside from manually uploading each of the 300 images?

2 Answers 2

2

If you're on WP 4.4 or newer this function is built in. Go to extra->export and select 'media'. This will download all attachment posts. You can import the file in your new install.

2
  • Where is 'extra'?
    – ΓΓIICK
    Commented Oct 28, 2016 at 17:38
  • 1
    Sorry, it's called Tools in english.
    – cjbj
    Commented Oct 28, 2016 at 18:41
1

WordPress doesn't use files for media, it uses posts of type attachment. These posts are what you see in the media library, and they have post meta that ties them to the files in the uploads folder.

This is why putting files in the uploads folder doesn't work, without the attachment posts they won't show up.

But since attachments are fundamentally just posts, we can import and export them, so your question now becomes:

Q: How do I export all posts of a single post type?

Specifically posts of type attachment?

There are many ways, but the most reliable method, that scales best and runs fastest is WP CLI in the terminal, e.g.:

wp export --dir="export_files" --max_file_size=3 --post_type="attachment"

This will export all your attachment posts as WXR files in a folder called export_files. It will also cap the size of these files to 3mb, ensuring that the import process never fails due to a lack of available RAM

Now all you need to do is visit your new site and import the files, making sure to check the box to download media. You can do this via the standard importer plugin, or in the terminal with WP CLI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.