Skip to content

Commit 2ebb78a

Browse files
committed
Added support for post_title
1 parent 50f907c commit 2ebb78a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Post_Command.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ public function list_( $_, $assoc_args ) {
418418
* default: publish
419419
* ---
420420
*
421+
* [--post_title=<post_title>]
422+
* : The post title.
423+
* ---
424+
* default:
425+
* ---
426+
*
421427
* [--post_author=<login>]
422428
* : The author of the generated posts.
423429
* ---
@@ -475,6 +481,7 @@ public function generate( $args, $assoc_args ) {
475481
'post_author' => false,
476482
'post_date' => current_time( 'mysql' ),
477483
'post_content' => '',
484+
'post_title' => '',
478485
);
479486
extract( array_merge( $defaults, $assoc_args ), EXTR_SKIP );
480487

@@ -495,7 +502,7 @@ public function generate( $args, $assoc_args ) {
495502
// Get the total number of posts.
496503
$total = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s", $post_type ) );
497504

498-
$label = get_post_type_object( $post_type )->labels->singular_name;
505+
$label = ! empty( $post_title ) ? $post_title : get_post_type_object( $post_type )->labels->singular_name;
499506

500507
$hierarchical = get_post_type_object( $post_type )->hierarchical;
501508

@@ -531,11 +538,11 @@ public function generate( $args, $assoc_args ) {
531538

532539
$args = array(
533540
'post_type' => $post_type,
534-
'post_title' => "$label $i",
541+
'post_title' => ! empty( $post_title && $i === $total ) ? "$label" : "$label $i",
535542
'post_status' => $post_status,
536543
'post_author' => $post_author,
537544
'post_parent' => $current_parent,
538-
'post_name' => "post-$i",
545+
'post_name' => ! empty( $post_title ) ? sanitize_title( $post_title . ( $i === $total ) ? '' : '-$i' ) : "post-$i",
539546
'post_date' => $post_date,
540547
'post_content' => $post_content,
541548
);

0 commit comments

Comments
 (0)