Skip to content

wp post term set --by=id with a non-existent ID removes all terms and reports success #690

Open

Description

@dhrupo

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 prints 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

CommandWithTerms::prepare_terms() drops IDs that do not match a term. When none match, set() calls wp_set_object_terms( $id, [], $taxonomy, false ), which replaces the existing terms with nothing. wp post term add --by=id takes the same path: it adds nothing and prints Success: Added term.. wp user term set|add use the same class.

Expected: an error, and the existing terms stay as they are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions