I need to be able to create posts in a custom post type with custom taxonomies from an XML file. It is from a job feed so when a job is added I need to be able to import it into wordpress. Do I just use wp_insert_post() ?
Leave a Reply
You must be logged in to post a comment.
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 WPfor 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.the FeedWordPress plugin (http://feedwordpress.radgeek.com/) allows you to pull in and publish feeds on a schedule, set categories (and a CPT, if one has already been established).