[wp-trac] [WordPress Trac] #34136: Allow register_post_type's rewrite to remove CPT slug

WordPress Trac noreply at wordpress.org
Tue Sep 30 11:05:28 UTC 2025


#34136: Allow register_post_type's rewrite to remove CPT slug
---------------------------+------------------------------
 Reporter:  BenRacicot     |       Owner:  (none)
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Rewrite Rules  |     Version:  4.3.1
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:
---------------------------+------------------------------

Comment (by drewmcnish):

 I took a look at this. When resolving pages and posts WordPress uses
 "?page_id=%post_id%" and "?p=%post_id%". When resolving custom posts
 however it defaults to "?post_type=slug". They are interchangeable though
 and you can use "?page_id=%post_id%" or "?p=%post_id%" for pages and posts
 and even your custom post.

 For clean URLs it resolves to "/index.php" (not your theme index.php but
 WordPress index.php). It then uses "$_SERVER[ 'REQUEST_URI']" to resolve
 the post. It already has to check the slug against internal posts and
 pages but seems to skip custom post types unless post_type is specified.
 Adding this will likely break backward compatibility.

 What is needed is to also check slugs against custom post types when the
 option is specified to treat them as internal post types. It then has to
 include them in the collision detection code.

 I would do this myself but am not familiar with the WordPress code.
 Perhaps someone else can make the changes as it's likely mostly just
 including the post type in the database lookups.

 The only reason I can think of why WordPress hasn't made the changes is
 because they don't know how or they don't care to provide the
 functionality.

 As for the people who can't comprehend why this should be a feature,
 clearly this is for the user to decide on a case by case basis no? There
 is clearly a use for it. For now I am just sticking to my own "$_SERVER[
 'REQUEST_URI']" in my plugin.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/34136#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list