Importing posts from XML into custom post type

I did a job like this. Essentially it is parse and wp_insert_post(), but there are couple of fragile things to be aware of:

  • you need some way to reliably track items to prevent duplicates, my approach was to save unique identifier from XML as post’s GUID in WP for some obscure reason WP wants GUID to be URL-like (not valid URL, but formatted like one) so it’s more reliable to go with custom field for identifiers that are not URLs;

  • wp_insert_term() checks for some user capabilities here and there. And in WP cron there is no user set up. I vaguely remember this caused me troubles with assigning custom taxonomy and since you need that – check source and properly test that code does work in cron.