Make WordPress Core

Opened 7 years ago

Closed 5 years ago

#41427 closed defect (bug) (invalid)

wp_set_object_terms creates new terms instead of linking existing ones

Reported by: martinkrcho's profile martin.krcho Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: Taxonomy Keywords: close reporter-feedback
Focuses: Cc:

Description

Function wp_set_object_terms doesn't behave as expected. When I pass an ID of an existing term (integer) as $terms parameter, it creates a new term with given ID as a slug. This is most likely due to one of the plugins I use, but the problem goes away when I change lines 2241 and 2242 in taxonomy.php to the following:

$term_ids[] = intval($term_info['term_id']);
$tt_id = intval($term_info['term_taxonomy_id']);

Would you consider adding this to the next version as a failsafe?

Change History (2)

#1 @boonebgorges
7 years ago

  • Keywords close reporter-feedback added

Be sure that the value you're passing as the $terms parameter is of type integer:

$term_id = (int) $term_id;
wp_set_object_terms( $post_id, $term_id, 'my_taxonomy' );

It's likely that you're passing in a numeric string (eg '3') rather than a true integer (eg 3).

#2 @boonebgorges
5 years ago

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

Closing on the basis of my previous comment. If this continues to be a problem, please reopen with details.

Note: See TracTickets for help on using tickets.