I know that I can clone or duplicate a post with several plugins. The one I use most often is https://wordpress.org/plugins/duplicate-post/. 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.
Cloning a post via wp-cli is little trickier. It needs two steps:
-
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
-
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"