Skip to content

Commit 3f4b03f

Browse files
committed
Add detail in README.md
1 parent b618e95 commit 3f4b03f

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ wp post
19651965
Creates a new post.
19661966

19671967
~~~
1968-
wp post create [--post_author=<post_author>] [--post_date=<post_date>] [--post_date_gmt=<post_date_gmt>] [--post_content=<post_content>] [--post_content_filtered=<post_content_filtered>] [--post_title=<post_title>] [--post_excerpt=<post_excerpt>] [--post_status=<post_status>] [--post_type=<post_type>] [--comment_status=<comment_status>] [--ping_status=<ping_status>] [--post_password=<post_password>] [--post_name=<post_name>] [--to_ping=<to_ping>] [--pinged=<pinged>] [--post_modified=<post_modified>] [--post_modified_gmt=<post_modified_gmt>] [--post_parent=<post_parent>] [--menu_order=<menu_order>] [--post_mime_type=<post_mime_type>] [--guid=<guid>] [--post_category=<post_category>] [--tags_input=<tags_input>] [--tax_input=<tax_input>] [--meta_input=<meta_input>] [<file>] [--<field>=<value>] [--edit] [--porcelain]
1968+
wp post create [--post_author=<post_author>] [--post_date=<post_date>] [--post_date_gmt=<post_date_gmt>] [--post_content=<post_content>] [--post_content_filtered=<post_content_filtered>] [--post_title=<post_title>] [--post_excerpt=<post_excerpt>] [--post_status=<post_status>] [--post_type=<post_type>] [--comment_status=<comment_status>] [--ping_status=<ping_status>] [--post_password=<post_password>] [--post_name=<post_name>] [--from-post=<post_id>] [--to_ping=<to_ping>] [--pinged=<pinged>] [--post_modified=<post_modified>] [--post_modified_gmt=<post_modified_gmt>] [--post_parent=<post_parent>] [--menu_order=<menu_order>] [--post_mime_type=<post_mime_type>] [--guid=<guid>] [--post_category=<post_category>] [--tags_input=<tags_input>] [--tax_input=<tax_input>] [--meta_input=<meta_input>] [<file>] [--<field>=<value>] [--edit] [--porcelain]
19691969
~~~
19701970

19711971
**OPTIONS**
@@ -2009,6 +2009,9 @@ wp post create [--post_author=<post_author>] [--post_date=<post_date>] [--post_d
20092009
[--post_name=<post_name>]
20102010
The post name. Default is the sanitized post title when creating a new post.
20112011

2012+
[--from-post=<post_id>]
2013+
Post id of a post to be duplicated.
2014+
20122015
[--to_ping=<to_ping>]
20132016
Space or carriage return-separated list of URLs to ping. Default empty.
20142017

@@ -2079,6 +2082,10 @@ wp post create [--post_author=<post_author>] [--post_date=<post_date>] [--post_d
20792082
$ wp post create --post_title='A post' --post_content='Just a small post.' --meta_input='{"key1":"value1","key2":"value2"}
20802083
Success: Created post 1923.
20812084

2085+
# Create a duplicate post from existing posts.
2086+
$ wp post create --from-post=123 --post_title='Different Title'
2087+
Success: Created post 2350.
2088+
20822089

20832090

20842091
### wp post delete

src/Post_Command.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct() {
7979
* : The post name. Default is the sanitized post title when creating a new post.
8080
*
8181
* [--from-post=<post_id>]
82-
* : The post id of a post to be duplicated.
82+
* : Post id of a post to be duplicated.
8383
*
8484
* [--to_ping=<to_ping>]
8585
* : Space or carriage return-separated list of URLs to ping. Default empty.
@@ -151,7 +151,7 @@ public function __construct() {
151151
* $ wp post create --post_title='A post' --post_content='Just a small post.' --meta_input='{"key1":"value1","key2":"value2"}
152152
* Success: Created post 1923.
153153
*
154-
* # Create a duplicate post with same post data.
154+
* # Create a duplicate post from existing posts.
155155
* $ wp post create --from-post=123 --post_title='Different Title'
156156
* Success: Created post 2350.
157157
*/
@@ -178,28 +178,28 @@ public function create( $args, $assoc_args ) {
178178
}
179179

180180
$array_arguments = array( 'meta_input' );
181-
$assoc_args = \WP_CLI\Utils\parse_shell_arrays( $assoc_args, $array_arguments );
182-
183-
if( isset( $assoc_args['from-post'] ) ) {
184-
$post = $this->fetcher->get_check( $assoc_args['from-post'] );
185-
$post_arr = get_object_vars( $post );
186-
$post_id = $post_arr['ID'];
187-
unset( $post_arr['post_date'] );
188-
unset( $post_arr['post_date_gmt'] );
189-
unset( $post_arr['guid'] );
190-
unset( $post_arr['ID'] );
191-
192-
if ( empty( $assoc_args['meta_input'] ) ) {
193-
$assoc_args['meta_input'] = $this->get_metadata( $post_id );
194-
}
195-
if ( empty( $assoc_args['post_category'] ) ) {
196-
$post_arr['post_category'] = $this->get_category( $post_id );
197-
}
198-
if ( empty( $assoc_args['tags_input'] ) ) {
199-
$post_arr['tags_input'] = $this->get_tags( $post_id );
200-
}
201-
$assoc_args = array_merge( $post_arr, $assoc_args );
181+
$assoc_args = \WP_CLI\Utils\parse_shell_arrays($assoc_args, $array_arguments);
182+
183+
if (isset($assoc_args['from-post'])) {
184+
$post = $this->fetcher->get_check($assoc_args['from-post']);
185+
$post_arr = get_object_vars($post);
186+
$post_id = $post_arr['ID'];
187+
unset($post_arr['post_date']);
188+
unset($post_arr['post_date_gmt']);
189+
unset($post_arr['guid']);
190+
unset($post_arr['ID']);
191+
192+
if (empty($assoc_args['meta_input'])) {
193+
$assoc_args['meta_input'] = $this->get_metadata($post_id);
194+
}
195+
if (empty($assoc_args['post_category'])) {
196+
$post_arr['post_category'] = $this->get_category($post_id);
202197
}
198+
if (empty($assoc_args['tags_input'])) {
199+
$post_arr['tags_input'] = $this->get_tags($post_id);
200+
}
201+
$assoc_args = array_merge($post_arr, $assoc_args);
202+
}
203203

204204
$assoc_args = wp_slash( $assoc_args );
205205
parent::_create( $args, $assoc_args, function ( $params ) {

0 commit comments

Comments
 (0)