You don’t have to export and then re-import, you can do it all via the API in one go, no XML required. here’s a quick example plugin:
<?php
/*
Plugin Name: WPA_convert_types
*/
function wpa_convert_types_page() {
add_management_page(
'WPA convert types',
'WPA convert types',
'manage_options',
'wpa_convert_types',
'wpa_convert_types_render_page'
);
}
add_action('admin_menu', 'wpa_convert_types_page');
function wpa_convert_types_render_page() {
if( isset( $_POST['wpa_do_convert'] ) ):
$args = array(
'posts_per_page' => -1
);
$posts_query = new WP_Query( $args );
if( $posts_query->have_posts() ):
global $post;
while( $posts_query->have_posts() ):
$posts_query->the_post();
$new_product = array(
'post_type' => 'product',
'post_status' => 'publish',
'post_title' => $post->post_title,
'post_content' => $post->post_content,
);
$product_id = wp_insert_post( $new_product );
// use get_post_meta, wp_get_object_terms
// to get meta and categories,
// use $product_id to associate with new product
// via wp_set_object_terms, add_post_meta
endwhile;
echo 'done';
endif;
else:
?>
<form method="post">
<input type="submit" name="wpa_do_convert" value="go">
</form>
<?php
endif;
}
You’ll have to add meta and category handling, see the comments below the wp_insert_post
line, but this should get you started.
EDIT- I keep forgetting that wp_insert_post
lets you set taxonomy terms within the function, see the codex entry for adding categories.