[wp-trac] [WordPress Trac] #53152: wp_set_object_terms ampersand in term name

WordPress Trac noreply at wordpress.org
Tue May 4 13:52:52 UTC 2021


#53152: wp_set_object_terms ampersand in term name
----------------------------+-----------------------------
 Reporter:  kapacity        |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  5.7.1
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 This is a follow-up to #32248.
 I believe we are running into this same core issue when using the
 wp_set_object_terms wp function. Here are the repro steps:

 For a given post and taxonomy call:
  wp_set_object_terms($post_id, ["foo & bar"], 'my_taxonomy', false);
  When the term does not yet exist it will be created with slug 'foo-bar'
 and name 'foo & bar in db.

 Rename term to "this & that" in admin, slug remains foo-bar and name is
 'this & that' in db.

 Now call
  wp_set_object_terms($post_id, ["this & that"], 'my_taxonomy', false);
  You get error 'A term with the name provided already exists in this
 taxonomy.'
  This is because the name matching logic in term_exists does not find the
 term by name since it is comparing the non escaped name 'this & that' to
 the escaped name in the db  'this & that' and determines it does not
 exist.

 I can work around this problem by calling the lower level wp functions
 myself, but this seems to be a bug.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53152>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list