Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#29624 closed defect (bug) (invalid)

wp_set_object_terms function append flag not working and overwriting existing terms

Reported by: rxnlabs's profile rxnlabs Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Taxonomy Keywords:
Focuses: Cc:

Description

When trying to append taxonomy terms to a post using the wp_set_object_terms function, setting the append argument to true still causes the function to overwrite any existing terms attached to the post.

The "if" statement used to check if the term should be appended is not is incorrect.

A simple fix would be changing the code on https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/taxonomy.php#L0.

On line 2629 from:

if ( ! $append )

to:

if ( $append )

This fixes the issue and terms are appended instead of being overwritten.

Change History (2)

#1 @boonebgorges
10 years ago

In 29997:

Add unit tests for 'append' argument of wp_set_object_terms().

See #29624.

#2 @boonebgorges
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I can't reproduce this. See the tests introduced in [29997].

I agree that the logic of the $append check at the beginning of wp_set_object_terms() seems a bit contradictory. But here's what's happening: The only place where these $old_tt_ids are used is later in the function, when deciding which old terms to delete. An array_diff() is run between $old_tt_ids and the tt_ids of the added terms, and the results of this diff are removed from the object. In other words: it's only when we are *not* appending that we ever need to delete any term relationships. See https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/taxonomy.php#L2683.

Going to close this one. If you continue to have problems, feel free to reopen with new details. Thanks for the report!

Note: See TracTickets for help on using tickets.