You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error out on post term set/add when no term ID exists - #692
wp post term set <id> <taxonomy> <term-id> --by=id removes every term from the object when none of the given IDs exist, and still reports success:
$ wp post term add 1 post_tag apple banana
Success: Added terms.
$ wp post term set 1 post_tag 9999 --by=id
Success: Set term.
$ wp post term list 1 post_tag --format=count
0
prepare_terms() drops IDs that do not match a term. When none match, set() passes an empty array to wp_set_object_terms() with $append = false, which removes all existing terms. add --by=id takes the same path: it adds nothing and prints Success: Added term..
set and add now stop with Error: Could not find any term with the given ID. (or IDs) when --by=id resolves to no terms, before anything is written. If at least one ID exists, the behavior is unchanged. remove --by=id already errors on this case (Please specify one or more terms, or use --all.), so it is left as is. The change also covers wp user term set|add, which share CommandWithTerms.
Testing
Adds a scenario to features/post-term.feature, after "Add terms by term id". It adds two tags to a post, runs set --by=id with one missing ID and add --by=id with two, checks both fail with exit code 1 and an empty STDOUT, then checks both tags are still attached.
Without the fix, the scenario fails because wp post term set 1 post_tag 9999 --by=id prints Success: Set term. with exit status 0, and the post is left with 0 tags (WordPress 7.1.4, MySQL 8.4).
With the fix, features/post-term.feature (7 scenarios) and features/user-term.feature (3 scenarios) pass on WordPress 7.1.4, MySQL 8.4.
PHPCS passes on src/WP_CLI/CommandWithTerms.php. The linter and Gherkin lint pass.
AI assistance: I used Claude Code to find this and write the change; I reviewed and ran everything myself.
Summary by CodeRabbit
Bug Fixes
Commands for adding or setting terms by ID now report an error when the specified IDs don’t match existing terms, rather than completing without a clear failure. Existing terms remain unchanged.
No actionable comments were generated in the recent review.
Walkthrough
When --by is supplied and term preparation returns no terms, the add and set commands now report an error. A feature scenario checks the error output and confirms that previously added terms remain listed.
Changes: Term ID validation
Layer / File(s)
Summary
Handle empty ID-based term results src/WP_CLI/CommandWithTerms.php, features/post-term.feature
The add and set commands report an error when --by is supplied and term preparation returns no terms. The error labels the input as ID or IDs based on the number of term arguments. The feature scenario checks the errors and verifies that previously added terms remain listed.
The commands reject unmatched term IDs before changing existing terms. No issue requiring a fix before merge was identified.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title describes the main change: reporting an error when no supplied post term ID exists.
Linked Issues check
[#690] CommandWithTerms::set() and add() stop before writing when no supplied IDs resolve. The shared implementation also covers user terms. The post-term scenario checks both errors and confirms …
Out of Scope Changes check
[#690] The shared command changes and post-term regression scenario address the linked issue. No unrelated changes are shown.
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check
Explanation
[#690] CommandWithTerms::set() and add() stop before writing when no supplied IDs resolve. The shared implementation also covers user terms. The post-term scenario checks both errors and confirms that existing tags remain attached. Matching IDs retain the existing behavior.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files. (1 skipped: 1 unsupported.)
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: dc4aa4f5-3276-4a6c-b512-68b3b01ac5e3
Commits
Reviewing files that changed from the base of the PR and between 47ff5a1 and bfe3ac3.
Files selected for processing: 2
features/post-term.feature
src/WP_CLI/CommandWithTerms.php
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #690
wp post term set <id> <taxonomy> <term-id> --by=idremoves every term from the object when none of the given IDs exist, and still reports success:prepare_terms()drops IDs that do not match a term. When none match,set()passes an empty array towp_set_object_terms()with$append = false, which removes all existing terms.add --by=idtakes the same path: it adds nothing and printsSuccess: Added term..setandaddnow stop withError: Could not find any term with the given ID.(orIDs) when--by=idresolves to no terms, before anything is written. If at least one ID exists, the behavior is unchanged.remove --by=idalready errors on this case (Please specify one or more terms, or use --all.), so it is left as is. The change also coverswp user term set|add, which shareCommandWithTerms.Testing
Adds a scenario to
features/post-term.feature, after "Add terms by term id". It adds two tags to a post, runsset --by=idwith one missing ID andadd --by=idwith two, checks both fail with exit code 1 and an empty STDOUT, then checks both tags are still attached.wp post term set 1 post_tag 9999 --by=idprintsSuccess: Set term.with exit status 0, and the post is left with 0 tags (WordPress 7.1.4, MySQL 8.4).features/post-term.feature(7 scenarios) andfeatures/user-term.feature(3 scenarios) pass on WordPress 7.1.4, MySQL 8.4.src/WP_CLI/CommandWithTerms.php. The linter and Gherkin lint pass.AI assistance: I used Claude Code to find this and write the change; I reviewed and ran everything myself.
Summary by CodeRabbit