创建自定义帖子类型,然后尝试此操作。(首先备份,因为这未经测试)。
<?php
// Get all posts in category "5"
$news_posts = get_posts(
array(
\'category\' => 5
)
);
// Loop through them
foreach($news_posts as $p):
// Update the post type
wp_update_post(
array(
\'ID\' => $p->ID,
\'post_type\' => \'news\'
);
);
// Delete term relationships for the post
wp_delete_object_term_relationships( $p->ID, \'post_tag\' );
wp_delete_object_term_relationships( $p->ID, \'category\' );
endforeach;
?>