1

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() ?

3
  • Can you share a link to your xml parser?
    – kaiser
    Jun 26, 2011 at 13:41
  • your question is way to general to answer but yeah all you need is wp_insert_post() and an XML parser.
    – Bainternet
    Jun 26, 2011 at 13:44
  • The XML is from broadbean jobs feed if that helps. My plan is to read in the feed and loop through and create the posts then from then on only do one job at a time so I don't get duplicates or see if there is a unique I'd to check against.
    – Lee
    Jun 26, 2011 at 15:19

2 Answers 2

1

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.

5
  • 1
    Since posting this I have now managed to get the data from a POST so i can use that to create the posts in WordPress. So i won't need a cron to trigger it as it will happen when the POST is sent. I need the ability to add custom fields to the custom post type and maybe taxonomies as well. Since this is a job posting i will have the usual salary, location etc would this be ebst suited to a custom psot type with custom fields do you think?
    – Lee
    Jul 4, 2011 at 13:38
  • @Lee yep, CPT seems fitting for such.
    – Rarst
    Jul 4, 2011 at 13:50
  • How easy do you think it would be to create a search for jsut the jobs, including searching the custom fields?
    – Lee
    Jul 4, 2011 at 14:15
  • @Lee native WP search kinda sucks, so it highly depends if you can find plugin that fits your spec or if you need to code that from scratch
    – Rarst
    Jul 4, 2011 at 14:20
  • I have read about limiting the search to a custom post type so I was thinking of doing that plus using the search everything plugin.
    – Lee
    Jul 4, 2011 at 14:55
1

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.