WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#10712 closed defect (bug) (fixed)

Sub categories automatically append a dash followed by the name of the parent

Reported by: guischarf Owned by:
Milestone: 3.0 Priority: high
Severity: normal Version: 3.0
Component: Taxonomy Keywords: subcategories
Focuses: multisite Cc:

Description

Hello,

I don't know whether this is a bug or a conceptual error. In 2.8.3 and 2.8.4, what happens is that, whenever a subcategory is created, WP modifies the title entered by the user, appending a dash and the name of the parent category.

Say, I have a parent category Frogs. If I create the subcategory Green Frogs and give it the title green-frogs, WordPress will modify my title and create green-frogs-frogs. To begin with, this defeats the purpose of the title field. If titles are to be generated by WP, the title field should be eliminated.

I found a way around this by creating the soon-to-be subcategory without a parent and then assign it a parent. For example, I create Green Frogs without a parent and give it the tittle green-frogs. Afterwards, I assign Green Frogs as a child of Frogs.

This behaviour, in my particular case, creates a problem, because I use category and subcategory titles to load images. If I create the subcategory Green Frogs I expect the application to load the image green-frogs.jpg, not green-frogs-frogs.jpg.

Attachments (2)

wp3.0-categories-subcategories-slug-issue.png (16.6 KB) - added by kpdesign 5 years ago.
wp3.0-categories-subcategories-slug-issue-multisite.png (14.9 KB) - added by kpdesign 5 years ago.

Download all attachments as: .zip

Change History (26)

comment:1 @guischarf6 years ago

  • Cc guischarf added

comment:2 @scribu6 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

Can't reproduce behaviour in WP 2.9-rare.

Created category Frogs.
Created sub-category Green Frogs.
Slug is green-frogs.

comment:3 follow-up: @guischarf6 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Hello, behaviour does not take place in WP 2.9, but in 2.8.3.

comment:4 @ryan6 years ago

This will happen if you already have a Green Frogs category elsewhere. The parent is appended to make the slug unique.

comment:5 @guischarf5 years ago

Not really. Take a look at this:

I found a way around this by creating the soon-to-be subcategory without a parent and then assign it a parent. For example, I create Green Frogs without a parent and give it the tittle green-frogs. Afterwards, I assign Green Frogs as a child of Frogs.

I am able to assign it the slug without appending the parent if a create the category and then assign it a parent. The behaviour is the same with any new sub-category we create. And I mean new, not-previously existing category.

comment:6 in reply to: ↑ 3 @scribu5 years ago

  • Milestone changed from Unassigned to 2.9.1
  • Resolution set to fixed
  • Status changed from reopened to closed

Replying to guischarf:

Hello, behaviour does not take place in WP 2.9, but in 2.8.3.

This is not going to be fixed in the 2.8 branch. Just upgrade to WP 2.9

comment:7 @westi5 years ago

  • Milestone changed from 2.9.1 to 2.9

comment:8 @kpdesign5 years ago

  • Milestone changed from 2.9 to 3.0
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 2.8.3 to 3.0

This issue is back. I opted to re-open this ticket rather than opening a new one. Apologies in advance if I made the wrong choice.

I am seeing the same behavior in 3.0-alpha as the OP was seeing in 2.8.3. Here is my setup:

  • WordPress 2.9.2, upgraded to 3.0-alpha single mode, running bleeding edge via the WordPress Beta Tester plugin.
  • After upgrading to 3.0, no changes were made at all to the settings and no other plugins installed.

I went to the Categories link and added the following:

  • WordPress (top-level category)
  • bbPress (subcategory of WordPress)
  • BackPress (subcategory of WordPress)
  • BuddyPress (subcategory of WordPress)

The only other category that existed when I did this was the default category (Uncategorized).

For all 3 subcategories, the parent slug was appended to the end of the subcategory slug (see attached screenshot). What Ryan said about appending the parent cat slug in order to make the subcategory slug unique if the same subcategory existed elsewhere isn't applicable here, as these are the only categories in this install.

I have to edit each subcategory and manually delete the parent slug after they are created.

comment:9 @markmcwilliams5 years ago

Well I'm able to reproduce what Kim gets!

comment:10 follow-up: @dd325 years ago

I'm not sure why this ticket was set to fixed, It should've been closed as wontfix.

The behaviour you are seeing is the correct behaviour.

If a term exists elsewhere with that slug, then newly created terms will have the parent's slug appended.

In your case, I believe this may be due to you having a 'bbpress' tag or similar?

However, This may be a change between 2.9 and 3.0 (Just as it was a change between 2.8 and 2.9 reported here), The slugs are being set as unique accross all taxonomies, and existing terms are not being re-used in different taxonomies (to inherit the same Name/slug)

comment:11 in reply to: ↑ 10 @kpdesign5 years ago

Replying to dd32:

I'm not sure why this ticket was set to fixed, It should've been closed as wontfix.

The behaviour you are seeing is the correct behaviour.

If a term exists elsewhere with that slug, then newly created terms will have the parent's slug appended.

In your case, I believe this may be due to you having a 'bbpress' tag or similar?

However, This may be a change between 2.9 and 3.0 (Just as it was a change between 2.8 and 2.9 reported here), The slugs are being set as unique across all taxonomies, and existing terms are not being re-used in different taxonomies (to inherit the same Name/slug)

This did not happen in 2.9, so the issue was fixed there. It has started again in 3.0.

There are no post tags in any of the installs (I don't use them), so it can't be finding a similar tag.

The attached screenshot is from a clean install - no content added or changed after install, only 1 new category and 3 new subcategories. The parent slug is being appended to every subcategory created.

To be sure it wasn't keying on the 'press' portion of the subcategory names (which it shouldn't), I added another subcategory 'hownowbrowncow', and the parent slug was appended to that as well.

I can understand doing that if WordPress finds another category, subcategory, or post tag exists with the same name, but each of these subcategory names are unique, so the parent slug should not be appended to it.

comment:12 @kpdesign5 years ago

Additional info:

If you create a sub-subcategory, the top-level category slug is being appended multiple times.

WordPress (slug: wordpress)
-- FordRanger (slug: fordranger-wordpress)
-- -- ChevyTahoe (slug: chevytahoe-fordranger-wordpress-wordpress)
-- -- -- ToyotaPrius (slug: toyotaprius-chevytahoe-fordranger-wordpress-wordpress-fordranger-wordpress-wordpress)

All of those subcategory names are unique in my test install.

This needs to be fixed, as I don't believe the slugs above are the intended behavior.

comment:13 @johnonolan5 years ago

  • Priority changed from normal to high

Tested in latest trunk and I can confirm that I'm able to replicate this issue. This is definitely not correct behavior - it makes no sense at all, and is not present in 2.9.2.

comment:14 @nacin5 years ago

(In [13845]) Bail in wp_unique_term_slug if the slug is unique and we don't need to come up with a new one. fixes #10712.

Noticed #12729 in the process.

comment:15 @nacin5 years ago

  • Component changed from General to Taxonomy

comment:16 @kpdesign5 years ago

  • Cc kpdesign added

Tested out fix in my dev install with the following results:

  • New unique subcategory slug does not have anything appended to it.
  • Adding new subcategory w/same name as another fails with warning at top of page that another category exists with the same slug, rather than appending parent slug.
  • Any attempt to change an existing slug to one that already exists fails with a warning.

I would much rather it work this way and allow the user to select their own unique slug than to have one auto-generated for them.

comment:17 @kpdesign5 years ago

  • Keywords multisite added

I've retested this on a 3.0-single WordPress install (latest nightly) and the issue is still fixed there.

I've tested this on a 3.0-multisite WordPress install (latest nightly) this evening, and the top-level category slugs are being appended multiple times when creating a subcategory or sub-subcategory with an existing name (see attached screenshot). (I did not choose either option in Global Terms in the Super Admin>>Options on this install.)

I know that the slug needs to be unique if it already exists; however, rather than appending the names of all the categories/subcategories above it, couldn't a unique number be appended to the slug instead?

comment:18 @wpmuguru5 years ago

(In [14234]) only append parent term slug until unique slug found, see #10712

comment:19 @ryan5 years ago

Just a reminder to all to remember to test taxonomy changes with global terms and multisite. I haven't noticed any problems yet, just a reminder. See also #13060.

comment:20 @kpdesign5 years ago

I updated to latest nightly (again) on my multisite install, then grabbed new copies of taxonomy.php and admin-ajax.php, uploaded to my server to get fixes from r14234 and r14229 and ran same tests w/out global terms setting. Now WordPress is only appending a parent slug to duplicate category name until a unique slug is found, so long/duplicate slug issue I reported seems to be resolved.

Per Ryan's note above, will now go back, enable Global Terms and run same test again. I'll post my results here.

comment:21 @dd325 years ago

(In [14238]) Remove stray svn:ignore property set in r14234. See #10712

comment:22 @scribu5 years ago

Related: #13119

comment:23 @kpdesign5 years ago

Finally had time to test this evening. Enabled global terms in updated multisite install (wp_sitecategories table created in database).

Added identical set of categories/subcategories to main site (/blog/) and 2nd site (created as a subdirectory).

Category list (both main and 2nd site):

Chevy Tahoe (slug: chevy-tahoe)
-- Ford Ranger (slug: ford-ranger-chevy-tahoe)
-- -- Toyota Prius (slug: toyota-prius-ford-ranger-chevy-tahoe)
-- Toyota Prius (slug: toyota-prius-chevy-tahoe)
Ford Ranger (slug: ford-ranger)
-- Chevy Tahoe (slug: chevy-tahoe-ford-ranger)
-- Toyota Prius (slug: toyota-prius-ford-ranger)
Toyota Prius (slug: toyota-prius)
-- Chevy Tahoe (slug: chevy-tahoe-toyota-prius)
-- Ford Ranger (slug: ford-ranger-toyota-prius)

Have assigned these categories to posts on both sites; category URLs are correct. I haven't seen any issues yet.

comment:24 @wpmuguru5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

Closing this pending someone reporting an issue.

Note: See TracTickets for help on using tickets.