How do I clone or duplicate a post with the WordPress Command Line Interface WP-CLI?

Cloning a post via wp-cli is little trickier. It needs two steps:

  1. Create a file where save the information of post. Suppose, following command create a file named file.txt from hello post (id 1). In this case file.txt which save on root directory.

    wp post get 1 > file.txt

  2. Create new post from this file. In our scenario file.txt saved all information of hello post. Following command create a post named duplicate

    wp post create ./file.txt --post_title="duplicate"

Leave a Comment