Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#41427 closed defect (bug) (invalid)

wp_set_object_terms creates new terms instead of linking existing ones

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

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
9 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
8 years ago

  • Milestone Awaiting Review
  • Resolutioninvalid
  • Status newclosed

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.