While WP-CLI doesn't have a built-in command for directly moving comments, you can achieve this by editing the comment's
comment_post_ID field. Here are two ways:
1. Using the wp comment edit command:
- Identify the comment ID: You'll need the ID of the comment you want to move. You can find this in the URL when editing the comment in the admin panel, or using the
wp comment listcommand with the--post_id=<source_post_id>flag to list comments on the source post. - Edit the comment: Run the following command, replacing
<comment_id>,<source_post_id>, and<target_post_id>with the actual values:
wp comment edit <comment_id> --post_id=<target_post_id>
e.g. wp comment update 319 --comment_post_ID=4539
This updates the comment_post_ID field of the comment, effectively moving it to the new post.
2. Using a plugin:
Several plugins offer comment management features, including moving comments. Consider these options:
- Tako Movable Comments: This plugin provides a dedicated interface for moving comments within your WordPress dashboard. You can locate the comment you want to move and choose the target post from a dropdown menu.
- WP CLI Manage Commands: This plugin extends WP-CLI with additional commands, including one for moving comments. You can use the
wp manage comment movecommand with various flags to move the comment directly from the command line.
Important notes:
- These methods will not move replies to the comment. You may need to move them manually or consider plugins that handle threaded comments.
- Always back up your database before making any changes.
- If you're not comfortable with the command line, using a plugin might be a safer option.