Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#31270 assigned defect (bug)

Unexpected slugs for same-title different-parents term creation

Reported by: dd32's profile dd32 Owned by: boonebgorges's profile boonebgorges
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Taxonomy Keywords: has-patch needs-unit-tests needs-refresh
Focuses: Cc:


When creating a new term which matches an existing terms name, it uses that slugs slug as the slug prefix, which can result in an unexpected term slug.

For example, take this:

Foo (slug: foo)
 - Bar  (slug: foo-bar)

If we now create a root level "Bar" term, it'll get a slug of foo-bar-2, when one would expect it to receive bar since no conflicting slug exists.

This is related directly to [28733] / #17689.

Unit test attached showing behaviour.

Attachments (2)

31270.ut.diff (1.5 KB) - added by dd32 9 years ago.
31270.patch (520 bytes) - added by tyxla 9 years ago.
In wp_insert_term() when initially figuring out a slug, make sure that existing term is considered only on the current term level.

Download all attachments as: .zip

Change History (10)

9 years ago

#1 @dd32
9 years ago

Looks like this has been kind of touched on in

9 years ago

In wp_insert_term() when initially figuring out a slug, make sure that existing term is considered only on the current term level.

#2 @tyxla
9 years ago

  • Keywords has-patch added

It appears that when determining the slug (when not specifically provided) in wp_insert_term(), if there is a term with the same name on any level, the slug of that term is used. This can be clearly seen at [28733] - lines 2441:2442. The issue can be resolved if a term with the same name is considered only when it is on the current term level. Attached a patch for that - 31270.patch.

Last edited 9 years ago by tyxla (previous) (diff)

#3 @snakefoot
9 years ago

This would also resolve #5034, which I have been waiting for :-). Would love to upgrade from WP2.0 to WP4.2 :-)

#4 @boonebgorges
9 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release

Yes, this is pretty much the same issue as #5034. 31270.patch looks good at a glance, but a change like this will need the support of a number of unit tests. I think we have some tests currently that describe the existing behavior, and those will have to be carefully reviewed and updated as necessary; new tests may have to be written for various combinations of same/different taxonomy, hierarchical/non-hierarchical taxonomy, same/different/no parent.

#5 @snakefoot
9 years ago

When looking at the trunk code for wp_insert_term(), then it already has a check with is_taxonomy_hierarchical() that verify combinations of slug+term within the same parent. Together with the protection of wp_unique_term_slug() (concat of parent-term with child-slug).

#6 @snakefoot
9 years ago

There is an issue with the query-parser, when having two similar slugs with different parents. The query-parser doesn't include the parent hierarchy when generating the SQL, and just picks a "random" slug.

I have attached a plugin to #5034, which implements a hack, but it would be nicer if the query-parser handled it.

Instead of a bug, then it is a feature just like #5034 :)

#7 @wonderboymusic
9 years ago

  • Milestone changed from Future Release to 4.4
  • Owner set to boonebgorges
  • Status changed from new to assigned

#8 @DrewAPicture
9 years ago

  • Keywords needs-refresh added
  • Milestone changed from 4.4 to Future Release

31270.patch needs a refresh and still needs unit tests to move forward. Punting.

Note: See TracTickets for help on using tickets.