3

I have a category Australia and have been experimenting with boboldehampsink import plugin.

After deleting categories and starting over the category Australia now has a slug called 'australia-6'. I just want 'australia' but i cant get rid of the hypen and 6.

I notice the content table has lots of entries for australia but no slugs so I'm wondering about the db schema for craftcms and how come i have got a stuck slug so quickly?

2

When you save an entry/category that is supposed to have its own URL, Craft will assign it a unique URI, based on the section/category group’s URL Format setting.

For example, let’s say you have a section called News, and its “Entries in this section have their own URLs” checkbox is checked, and it has this URL Format:

news/{slug}

When you save a News entry, Craft will assign it a unique URI based on that URL Format. If the entry’s slug is “foo”, then the first URI Craft will try to assign it will be “news/foo”.

However, if that URI is already taken by another entry/category (or some third party element type), Craft will increment the slug and try again:

  • news/foo-1
  • news/foo-2
  • news/foo-3
  • etc.

(If incrementing the slug has no effect on the URI – because the URL Format doesn’t actually contain a {slug} token – then Craft will simply give up and add a validation error to the element.)

Once it has found a URI that is actually unique, it will update the element’s Slug with the incremented version.

So in your case, when you save a category with the slug “australia” and it becomes “australia-6“, that means that you have 6 other elements that had been saved with the slug “australia” before it, with the same URL Format that your current category has, and so “australia-6” was just the first slug Craft could find that resulted in your category having a unique URI.

To find out which elements your category’s URI is conflicting with, you can go to Entries > All Entries, and search for slug:australia, and click through each of your category groups in the Categories tab, searching for slug:australia in each of them.

| improve this answer | |
  • Thanks Brandon for the detailed explanation. I understand the auto-increment of slug URIs for uniqueness. This is for a category as opposed to an entry but I see categories have slug entries too. The thing is there are no other Australia entries anywhere in the admin interface - but there are entries in the craft_content table or Australia. So I was expecting 'australia-6' to be changeable. – joomkit Oct 2 '15 at 7:50
  • 1
    Actually found the slugs in i18n table and removed them and element ids. This now allows me to recreate Australia slug as desired :) – joomkit Oct 2 '15 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.