문제

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?

도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top