WordPress offers an easy way to import and export its data using XML. It’s done with a GUI-based built-in importer. What I’d like to do however, is to be able to import certain XML files from within my theme (upon activation or after executing a function).
My case:
While there are a few plugins that can create dummy content for you, I couldn’t find any way to do what I’m trying to do – import a set of ACF fields stored in XML file.
Is there any way to do it?
Update: This function is meant to deal with XML data and is limited to ACF up to version 4. ACF 5 exports its fields as JSON data.
The solution turned into a WordPress plugin.
Here’s the solution to my problem.
Here’s how to use it:
Function expects at least
$xml_string
parameter to be passed. It should contain the contents of the XML file that is produced by ACF plugin upon export of an ACF field (post ofacf
type).The function will try to create one new ACF post unless one already exists, and then populate it with fields. To insert more than one field (a clone) with the same title, you should pass
true
as a second parameter.There are a few issues still to be addressed, but the function in its current state should be usable