I’m in the process of moving a site from an old CMS to WordPress, and I’m taking advantage of the WXR format.
I’ve been able to get the posts into WordPress with featured images, categories, tags, and comments intact, but I’m hung up on custom fields.
The entries for this particular site use subtitles, for which I’ve created a custom field in the WP installation. It shows up in the WXR like so:
<wp:postmeta>
<wp:meta_key>subtitle</wp:meta_key>
<wp:meta_value><![CDATA[Subtitle Goes Here]]></wp:meta_value>
</wp:postmeta>
I’ve duplicated this in the class I’m using for this export, and I’ve verified that the information is being saved in the wp_postmeta table in the database:
meta_id | post_id | meta_key | meta_value
447 | 2 | subtitle | Subtitle Goes Here
However, when I pull up the post, the subtitle does not display. It’s also not there when I edit the post.
When I edit the post and add a subtitle using WordPress, it adds a second row in wp_postmeta and then displays properly.
I’m having trouble finding anything around the web or on SO that addresses this, so I’m wondering if:
- Does anyone else have experience importing values into custom fields?
- If so, has anyone encountered (and hopefully overcome) this issue?
Thanks in advance!
Just in case anyone needs the answer to this one: the problem came from using the Advanced Custom Fields plugin.
The culprit was the
get_field()function created by ACF.To fix the problem, instead of using:
Use:
Check out the WordPress Codex for more info on
get_post_meta().Hopefully this’ll save someone some headache in the future.