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

I know that I can clone or duplicate a post with several plugins. The one I use most often is However I am using the WP-CLI more and more lately and I would like to be able to duplicate or clone a post from the command line.

Any suggestions would be appreciated.

3 s

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