WordPress.org

Make WordPress Core

Opened 19 months ago

Closed 10 months ago

Last modified 10 months ago

#36690 closed enhancement (fixed)

Improve documentation on deleting all terms associated with an object

Reported by: barryceelen Owned by: SergeyBiryukov
Milestone: 4.8 Priority: normal
Severity: normal Version: 4.6
Component: Taxonomy Keywords: has-patch 2nd-opinion good-first-bug
Focuses: docs Cc:

Description

While looking for a way to delete all terms related to an object I first looked at wp_remove_object_terms(). That function however expects the slug(s) or ID(s) of the term(s) to remove as a parameter and cannot be used for removing all terms at once.

The right way to do this appears to be passing an empty array or null/false for the $terms parameter to the wp_set_object_terms() function.

It would be helpful to update the documentation of the wp_set_object_terms() function (or both).

Attachments (2)

36690.diff (1.4 KB) - added by barryceelen 19 months ago.
Updates the description of the $terms param
36690.1.diff (1.0 KB) - added by barryceelen 13 months ago.

Download all attachments as: .zip

Change History (10)

@barryceelen
19 months ago

Updates the description of the $terms param

#1 @barryceelen
19 months ago

  • Focuses docs added
  • Keywords has-patch added

This ticket was mentioned in Slack in #docs by morganestes. View the logs.


14 months ago

#3 @morganestes
14 months ago

I think we should avoid using mixed if we know exactly what to expect for a parameter's value, so @param array|int|string $terms is fine, but the order in the description should match the order of the types.

#4 @morganestes
14 months ago

  • Keywords 2nd-opinion good-first-bug added

#5 @barryceelen
13 months ago

@morganestes Thanks for your feedback. I replaced mixed with array|int|string. Should there also be a reference added to wp_remove_object_terms()? That would probably be the first function one would look at when trying to delete all terms associated with an object.

#6 @SergeyBiryukov
10 months ago

  • Milestone changed from Awaiting Review to 4.7.2

#7 @SergeyBiryukov
10 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 39893:

Docs: In wp_set_object_terms(), add a note that passing an empty value as $terms argument will remove all related terms.

Props barryceelen.
Fixes #36690.

#8 @SergeyBiryukov
10 months ago

  • Milestone changed from 4.7.2 to 4.8
Note: See TracTickets for help on using tickets.