A alternative for custom source. I had read this answers, but the plugins are old or with to much options and I will leave my small solution.
I never knew it’s that simple to copy all comments from one WordPress post to another. The following snippet copies all posts from $post_id
to $new_post_id
.
<?php
// copy all comments from post $post_id to post $new_post_id
foreach ( get_comments( array( 'post_id' => $post_id ) ) as $comment ) {
$comment->comment_post_ID = $new_post_id;
wp_insert_comment( (array) $comment );
}
get_comments()
is a convenience function around WP_Comment_Query, so if you put this snippet inside a loop you can omit the ‘post_id’ parameter.
Oh, and if you don’t need to copy but to move the comments, you may be better off by just firing some good old SQL against your database:
<?php
function move_comments( $from_post_id, $to_post_id ) {
global $wpdb;
$sql = sprintf(
'UPDATE %s SET comment_post_id=%s WHERE comment_post_id=%s;',
$wpdb->comments,
(int) $to_post_id,
(int) $from_post_id
);
$wpdb->query( $sql );
}