Massive photogallery import

How will you represent the galleries on the new site? Will each gallery be a post with a standard shortcode?

If so, you’ll basically only need the url for each image on the old site (plus post heading/text and image descriptions if needed), and you can create a WXR import file to import everything into the new site.

Example, an import file with a gallery with two images (tested on WP 4.2.2):

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
    xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:wp="http://wordpress.org/export/1.2/" >

    <channel>
        <wp:wxr_version>1.2</wp:wxr_version>

        <!--A post with a little text and of course a gallery of images-->
        <item>
            <title>My first gallery</title>
            <dc:creator><![CDATA[admin]]></dc:creator>
            <description></description>
            <content:encoded><![CDATA[
<p><b>Welcome to my first gallery!</b> Here are the images:</p>

]]></content:encoded>
            <excerpt:encoded><![CDATA[]]></excerpt:encoded>
            <wp:post_id>300</wp:post_id>
            <wp:post_date>2015-03-05 16:20:00</wp:post_date>
            <wp:status>publish</wp:status>
            <wp:post_parent>0</wp:post_parent>
            <wp:post_type>post</wp:post_type>
        </item>

        <!--The images attached to that post-->
        <item>
            <title>Picture of a cat</title>
            <dc:creator><![CDATA[admin]]></dc:creator>
            <description></description>
            <excerpt:encoded><![CDATA[This is a picture of a cat I found]]></excerpt:encoded>
            <wp:post_id>301</wp:post_id>
            <wp:post_date>2015-03-05 16:21:00</wp:post_date>
            <wp:status>inherit</wp:status>
            <wp:post_parent>300</wp:post_parent>
            <wp:post_type>attachment</wp:post_type>
            <wp:attachment_url>https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg</wp:attachment_url>
        </item>
        <item>
            <title>Picture of a dog</title>
            <dc:creator><![CDATA[admin]]></dc:creator>
            <description></description>
            <excerpt:encoded><![CDATA[]]></excerpt:encoded>
            <wp:post_id>302</wp:post_id>
            <wp:post_date>2015-03-05 16:22:00</wp:post_date>
            <wp:status>inherit</wp:status>
            <wp:post_parent>300</wp:post_parent>
            <wp:post_type>attachment</wp:post_type>
            <wp:attachment_url>https://upload.wikimedia.org/wikipedia/commons/b/b7/Langhaardackel_merlin_2005.jpg</wp:attachment_url>
        </item>
    </channel>
</rss>

This is close to the minimum of info required to do an import, but there are many other settings that can be added in the <item> elements if you need them, for example categories.

A few things to note:

  • Titles (<title>) must be unique across all posts and attachments, or WordPress will skip them during import.
  • I believe a post must come before its images in the import file.
  • Keep track of your IDs. To hook up each image to their corresponding galleries, you must set each post and image ID (<wp:post_id>) yourself.
    • In the shortcodes, you need to insert the images’ IDs.
    • Each image should be registered as an attachment to its gallery post (<wp:post_parent>).
    • .. so start with an ID that is larger than any current post/attachment ID on the new site and count your way up (see where the IDs 300, 301 and 302 are used in the example).
  • <wp:attachment_url> is the url on the old site, where WordPress can fetch the images from.

Once you have a complete import file, go to Tools > Import > WordPress

  • (You may have to install the “WordPress Importer” plugin if you don’t have it already)
  • Choose your file and click “Upload file and import”.
  • On the next screen, map old user to new users (in my example, all items were <dc:creator>-ed by “admin”, so I just map them to the new site admin here), and most importantly, check “Download and import file attachments”, to make the new site download the image files from the old site (via the urls in <wp:attachment_url>).

Import WordPress