I checked it because I needed to do it at work, so I made a note.
The destination WordPress used a custom post type and ACF, so it was a bit annoying.
I decided to create WordPress XML, a WordPress import tool, from my own CMS data and migrate the data.
As you can see by writing the WordPress site using ACF to XML and looking inside, ACF seems to have an identifier like field_5671e74fc8c5e
assigned to each field, so this is necessary when creating WordPress XML.
So, the setup is as follows.
The rough structure of XML is as follows.
ʻAuthor,
category, and
term` correspond to the WordPress users, categories, and terms.
ʻItem contains not only articles and pages, but also images and ACF custom fields in ʻitem
.
The value of the custom field registered in each article is in postmeta
.
An ID is assigned to ʻauthor,
category,
term, and ʻitem
, and they are used for parent-child relationships and for specifying images defined in item.
By the way, ʻauthor` seems to be able to be imported without it.
The image is registered as ʻitem`.
The URL of the image is defined as a child element named ʻattachment_url`.
If you register ʻitem` that represents an article as a parent element, it will be imported properly as an image associated with that article.
The custom field of the image contains the ID of the image defined in item.
The data of the custom field is in postmeta
, but when there is a text field named" year ", it looks like this.
<wp:postmeta>
<wp:meta_key><![CDATA[year]]></wp:meta_key>
<wp:meta_value><![CDATA[2015]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_year]]></wp:meta_key>
<wp:meta_value><![CDATA[field_5670f2bfd2c5a]]></wp:meta_value>
</wp:postmeta>
In order to create XML for import, you need to know year
and field_5670f2bfd2c5a
.
For example, if there is a repeating field called ʻimages, and there are multiple images called ʻimage
and a text field called caption
in it, it will be postmeta
as shown below.
The 2
on the third line seems to contain the defined number of elements.
<wp:postmeta>
<wp:meta_key><![CDATA[images]]></wp:meta_key>
<wp:meta_value><![CDATA[2]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_images]]></wp:meta_key>
<wp:meta_value><![CDATA[field_5670f0d3391f8]]></wp:meta_value>
</wp:postmeta>
<!--First image-->
<wp:postmeta>
<wp:meta_key><![CDATA[images_0_image]]></wp:meta_key>
<wp:meta_value><![CDATA[10]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_images_0_image]]></wp:meta_key>
<wp:meta_value><![CDATA[field_5670f2bad2c5a]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[images_0_caption]]></wp:meta_key>
<wp:meta_value><![CDATA[Image 1]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_images_0_caption]]></wp:meta_key>
<wp:meta_value><![CDATA[field_5670f2bfr2c5a]]></wp:meta_value>
</wp:postmeta>
<!--Second image-->
<wp:postmeta>
<wp:meta_key><![CDATA[images_1_image]]></wp:meta_key>
<wp:meta_value><![CDATA[11]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_images_1_image]]></wp:meta_key>
<wp:meta_value><![CDATA[field_5670f2bad2c5a]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[images_1_caption]]></wp:meta_key>
<wp:meta_value><![CDATA[Image 2]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_images_1_caption]]></wp:meta_key>
<wp:meta_value><![CDATA[field_5670f2bfr2c5a]]></wp:meta_value>
</wp:postmeta>
You can see the import process by looking at the * WordPress Import Tool * plugin code. Since there are only 2 files, I think it's faster to try putting debug code in the code of the * WordPress import tool * plugin than trying hard by trial and error of XML.
By the way, the import process is roughly like the following flow.
,
category,
term, and ʻitem
.ʻItem (probably
category`) controls not to import the same thing by looking at the ID, so if you do not properly squeeze the ID, it will not be imported for some reason. .. (hooked on.)
I've posted a Python script I made for work on GitHub, so if you think you can use it, please use it.
I'm using arrow for processing around the date, so just put this in with pip install arrow
.
ʻExamples / my_wordpress.py` is an example of a Python script that actually generates XML.
I haven't tried category
and term
because I didn't actually use them.
Please use at your own risk.
Recommended Posts