diff --git a/features/post-term.feature b/features/post-term.feature index 67993d256..7fcb39612 100644 --- a/features/post-term.feature +++ b/features/post-term.feature @@ -201,6 +201,27 @@ Feature: Manage post term | term_id | name | slug | | 3 | 4 | 4 | + Scenario: Remove a term that is not assigned to the post + Given a WP install + + When I run `wp post term add 1 post_tag apple` + And I run `wp term create post_tag banana` + Then STDOUT should not be empty + + When I try `wp post term remove 1 post_tag banana` + Then STDERR should be: + """ + Error: Failed to remove term. + """ + And STDOUT should be empty + And the return code should be 1 + + When I run `wp post term list 1 post_tag --field=slug` + Then STDOUT should be: + """ + apple + """ + Scenario: Remove all terms from post Given a WP install diff --git a/src/WP_CLI/CommandWithTerms.php b/src/WP_CLI/CommandWithTerms.php index a70347233..07f521638 100644 --- a/src/WP_CLI/CommandWithTerms.php +++ b/src/WP_CLI/CommandWithTerms.php @@ -211,7 +211,7 @@ public function remove( $args, $assoc_args ) { $label = count( $terms ) > 1 ? 'terms' : 'term'; - if ( is_wp_error( $result ) ) { + if ( ! $result || is_wp_error( $result ) ) { WP_CLI::error( "Failed to remove {$label}." ); }