WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 2 years ago

#15082 closed defect (bug) (fixed)

Custom post type empty slug breaks permalinks for pages

Reported by: firebird75 Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.0.1
Component: Posts, Post Types Keywords: 2nd-opinion
Focuses: Cc:

Description

If I register a custom post type using the register_post_type function and I pass the following parameter :

rewrite => array('slug' => )

If the blog permalink structure is set to /%postname%/, then it breaks the rewriting rules for pages (post of type page). They return a 404 error when you try to open it. You need to save at least one page after having registered the custom post type to see the issue.

Setting the custom post type slug to the value is made to have custom post type permalink structure match the blog permalink structure (ie only /%postname%/ in the url).

Attachments (1)

15082.diff (564 bytes) - added by nacin 3 years ago.
Prevent you from shooting yourself in the foot. Not convinced here, as they do work I guess, it just breaks something else.

Download all attachments as: .zip

Change History (14)

comment:1 firebird754 years ago

  • Cc autremonde75@… added

comment:2 scribu4 years ago

First of all, /%postname%/ is not a very efficient permalink structure:

http://dougal.gunters.org/blog/2009/02/04/efficient-wordpress-permalinks

The following article explains why page permalinks are broken:

http://ottopress.com/2010/category-in-permalinks-considered-harmful/

comment:3 follow-up: firebird754 years ago

Well, I understand that there are some drawbacks around using /%postname%/ but fact is that it is very widely used right now. I'd like to avoid the SEO debate around it, there are as many different points of view as people on that ;)

If I am not using the register post type but rather directly tweak WP to work with a custom post type, I don't fall into this issue.

I don't know if this is something that can be fixed but it would be nice, for those that like the simple permalink structure...

comment:4 nacin4 years ago

You can always set rewrite to false and handle it yourself.

comment:5 in reply to: ↑ 3 scribu4 years ago

Replying to firebird75:

Well, I understand that there are some drawbacks around using /%postname%/ but fact is that it is very widely used right now. I'd like to avoid the SEO debate around it, there are as many different points of view as people on that ;)

I was refering strictly to performance, not SEO.

comment:6 firebird754 years ago

@nacin : yes that's right, this is a possibility. I have absolutely no idea of how to achieve that but I could do some researches. Beside that, I can see how complex it is to tweak WP when you don't use the regular path so if I can avoid it ;)

@scribu : you are right, there is a performance impact but based on my experience, it won't multiply the page load time by 10... It is marginal so most users won't care about it and keep the permalink structure they prefer...

nacin3 years ago

Prevent you from shooting yourself in the foot. Not convinced here, as they do work I guess, it just breaks something else.

comment:7 nacin3 years ago

  • Keywords 2nd-opinion added

Attached a patch that prevent you from shooting yourself in the foot. Not convinced here, as they do work I guess, it just breaks something else.

comment:8 firebird753 years ago

Thanks for this Nacin!

If I understand well, you patch will prevent plugins from setting the slug to an empty value and then in that case default the slug to include the post_type, right?

This is probably a good idea as it will prevent the bug from showing up. It removes a bit of flexibility but since this one isn't working right now, it is probably better this way.

comment:9 scribu3 years ago

Related: #15324

comment:10 follow-up: nacin3 years ago

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

(In [17298]) Don't allow an empty rewrite slug for CPT. If you need something like this, do rewrite=>false. fixes #15082.

comment:11 nacin3 years ago

  • Milestone changed from Awaiting Review to 3.1

comment:12 in reply to: ↑ 10 ciantic2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 3.0.1 to 3.3.1

Replying to nacin:

(In [17298]) Don't allow an empty rewrite slug for CPT. If you need something like this, do rewrite=>false. fixes #15082.

How? There is gazillion ways to do this by Googling, but most of them overtly complicated for what it should be... Can't find the WP3.3 specific answer though! Some uses htaccess, some uses multiple tricks to rewrite the slug part with replacing string at some "handy spot".

Why can't there be API just like for regular post_type=post, where one can define "/%postname%/" in WP 3.3?

I know this is not Q&A, so I've started "Wordpress 3.3 custom post type with /%postname%/" in Wordpress StackExchange.

comment:13 SergeyBiryukov2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed
  • Version changed from 3.3.1 to 3.0.1

This ticket was closed on a completed milestone. I guess wp-hackers list would be the proper place for the discussion.

Version number indicates when the bug was initially introduced/reported.

Note: See TracTickets for help on using tickets.