admin管理员组

文章数量:1279145

A client just created a post with a really long slug (90 characters), no special characters (other than hyphens) etc.

Whenever the link to that post was clicked, including the "Preview" or "View this Post" links from the Admin back end, a 404 was generated.

Once we manually trimmed the slug, everything worked as expected. Is this a "feature" or a "bug"?

EDIT: a Note for all those talking about DB limits.

If I were hitting the DB field limit, then the slug itself would be truncated. Think about it for a second. In the case of most WP installations, wp_posts.post_name is VARCHAR(200). So, let's say that someone types in a title with > 200 chars. What happens? The slug gets truncated to 200 chars and stored in wp_posts.post_name. It's not like someone is going in and typing the full title of the post in the browser address bar, substituting the spaces with dashes right? The URL is being generated by WordPress, and it's getting the URL from the wp_posts.post_name table and just putting that in the href attribute of the anchor tag. So there's not going to be a disparity there. The whole DB thing is a red herring.

In any case, the slug in question is only 90 chars, so it has nothing to do with DB limits.

Are there any known limitations around rewrite?

A client just created a post with a really long slug (90 characters), no special characters (other than hyphens) etc.

Whenever the link to that post was clicked, including the "Preview" or "View this Post" links from the Admin back end, a 404 was generated.

Once we manually trimmed the slug, everything worked as expected. Is this a "feature" or a "bug"?

EDIT: a Note for all those talking about DB limits.

If I were hitting the DB field limit, then the slug itself would be truncated. Think about it for a second. In the case of most WP installations, wp_posts.post_name is VARCHAR(200). So, let's say that someone types in a title with > 200 chars. What happens? The slug gets truncated to 200 chars and stored in wp_posts.post_name. It's not like someone is going in and typing the full title of the post in the browser address bar, substituting the spaces with dashes right? The URL is being generated by WordPress, and it's getting the URL from the wp_posts.post_name table and just putting that in the href attribute of the anchor tag. So there's not going to be a disparity there. The whole DB thing is a red herring.

In any case, the slug in question is only 90 chars, so it has nothing to do with DB limits.

Are there any known limitations around rewrite?

Share Improve this question edited May 23, 2012 at 20:21 Tom Auger asked May 23, 2012 at 15:34 Tom AugerTom Auger 7,0969 gold badges63 silver badges84 bronze badges 1
  • 2 You can use a free tool like MySQL workbench to check the datatype (and maximum length if any) of any wordpress field as defined in the corresponding wordpress table/column – Jordi Cabot Commented May 23, 2012 at 16:13
Add a comment  | 

3 Answers 3

Reset to default 11

Due to wp_posts table structure the length of post_name column (the column for slugs) is equal to 200 characters.

I guess it doesnt have a limit by it self but the property of the field in the database for slugs might be set to a max length.

So check the Database!

Probably the problem wasn't even directly WordPress/database related at all ...

But the length of the URL exceeded 255 characters (and not all web-browser do like that).

What happened here might have been an URL longer than 255 chars, which got truncated by the browser's address-bar when opening it ... causing the retrieval of a bad permalink ... which resulted in a 4o4.

So assumable the maximum slug-length might be:

255 - the length of (Protocol + FQDN + permalink structure) ...

  • based on a browser's hard limit.

But it cannot be longer than 200 chars ...

  • based on the post_name's field size.

Even if somethings else might have caused the 4o4 in this particular case.

It could have been a character which wasn't properly url_encoded as well, reasons for 4o4's are quite endless ... ever considered a bad cluster on HDD or a faulty RAM module? :)

本文标签: Is there a maximum slug length