Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking to do a custom import from a custom cms to wordpress. Looking at the export/import files in wordpress, I can get match most of the structure. Though, it is missing the relationships for custom taxonomies and posts when exporting/importing.

Is there a fix for this or would it be easier to not use wordpress's import script? Rather, write custom SQL to handle it all.

Also, as I am developing this new site the content in the old site (custom cms) is still being updated. There will be a freeze a few days before launch, where I can do another db dump and reimport. Though, the issue I'm foreseeing is that I will need to delete all posts and relationships and reimport the content. Is there an easy way to delete all posts and relationships to prevent any duplicates and reimport the content?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

It shouldn't be hard to add handling for custom post types or taxonomies within a custom importer for WordPress. You'll just need to make sure that your custom post types and taxonomies are registered before the importer runs. Once registered, you can use wp_insert_post() and wp_set_object_terms() on these custom types. This will likely end up being a much better solution than trying to write custom SQL as it fills in a lot of the extra fields that aren't always obvious, like term object counts, etc.

Whenever I'm working on a script to import data from another system, I've always created nuke functions, for the reason you mentioned, and just because importing data is always a bunch of trial and error. The function usually just consists of a single loop to call wp_delete_post() for each post. Depending on the import, I may also add another one to call wp_delete_term() on each term in the database.

$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type in ('post', 'attachment', [...other post types])");
foreach($post_ids as $post_id) {
    wp_delete_post($post_id, true);
}
share|improve this answer
    
I'm going to use the Wordpress Importer (wordpress.org/extend/plugins/wordpress-importer) and format the old site's content into a WRX with the addition of a couple of custom elements. Thanks for your help. It will be trial and error from here. Your nuke function will definitely be of use. –  jaysonp Oct 26 '10 at 6:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.