diff --git a/features/term.feature b/features/term.feature index 91781bdb90..d2e45f1ea3 100644 --- a/features/term.feature +++ b/features/term.feature @@ -92,3 +92,22 @@ Feature: Manage WordPress terms """ My Test Category """ + + Scenario: Fetch term url + When I run `wp term create category "First Category" --porcelain` + And save STDOUT as {TERM_ID} + And I run `wp term create category "Second Category" --porcelain` + And save STDOUT as {SECOND_TERM_ID} + + When I run `wp term url category {TERM_ID}` + Then STDOUT should be: + """ + http://example.com/?cat=2 + """ + + When I run `wp term url category {TERM_ID} {SECOND_TERM_ID}` + Then STDOUT should be: + """ + http://example.com/?cat=2 + http://example.com/?cat=3 + """ diff --git a/php/commands/term.php b/php/commands/term.php index c92fb8b263..8df6543672 100644 --- a/php/commands/term.php +++ b/php/commands/term.php @@ -409,11 +409,14 @@ public function generate( $args, $assoc_args ) { * wp term url post_tag 123 324 */ public function url( $args ) { - $term_link = get_term_link( (int)$args[1], $args[0] ); - if ( $term_link && ! is_wp_error( $term_link ) ) { - WP_CLI::line( $term_link ); - } else { - WP_CLI::error( "Invalid term." ); + $term_ids = array_slice( $args, 1 ); + foreach ( $term_ids as $term_id ) { + $term_link = get_term_link( (int)$term_id, $args[0] ); + if ( $term_link && ! is_wp_error( $term_link ) ) { + WP_CLI::line( $term_link ); + } else { + WP_CLI::warning( sprintf( "Invalid term %s.", $term_id ) ); + } } }