I have this scenario: about 200 photo galleries to recreate in Wordpress from an old wordpress site.

All I have is the .xml WXR for the post_type "photogallery" that basically creates the gallery and attachs to it a bunch of image ids.

Unfortunately I can't export the "complete XML" (with images, ids and attached posts) nor access the dB.

So basically I should create a script that:

Reads the exported XML, retrieve the original URL for the gallery (the old site is still alive) open the URL, get the image in a specific and the text in and load it in wordpress, using the text as the image description, and associate it with the post_id found in the XML, open the link for the next image in the gallery (for example simulating a click over "next" button), and loop until all the images in the gallery have been loaded (average 10 to 15 for each gallery).

Any suggestion?


How will you represent the galleries on the new site? Will each gallery be a post with a standard [gallery ids=...] 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:wp="http://wordpress.org/export/1.2/" >


        <!--A post with a little text and of course a gallery of images-->
            <title>My first gallery</title>
<p><b>Welcome to my first gallery!</b> Here are the images:</p>
[gallery ids=301,302]
            <wp:post_date>2015-03-05 16:20:00</wp:post_date>

        <!--The images attached to that post-->
            <title>Picture of a cat</title>
            <excerpt:encoded><![CDATA[This is a picture of a cat I found]]></excerpt:encoded>
            <wp:post_date>2015-03-05 16:21:00</wp:post_date>
            <title>Picture of a dog</title>
            <wp:post_date>2015-03-05 16:22:00</wp:post_date>

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 [gallery ids=...] 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

  • Yes, this is the plan. Do you have a solution . – user3590313 Jul 11 '15 at 7:34
  • Yes, I have added an example. – Sphinxxx Jul 11 '15 at 23:18
  • Ok thanks. It should work. The problem is that I have thousands of images. More than 200 gallery with 10 to 20 images each. So I do need a script that basically should create the xml. Starting from the WXR, it should crawl each gallery url, retrieve information parsing the html page (that part is easy) store the information in the xml file, simulate a click to open the next image of the gallery and keep going. The theory isn't that hard. But I'm not properly skilled. – user3590313 Jul 12 '15 at 19:38
  • Ok. You could start by looking into web scraping/crawling to to download all content (at least the html) to your computer, and then structure stuff to create the WXR from there. For example, have a look at Scrapy – Sphinxxx Jul 12 '15 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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