[wp-trac] [WordPress Trac] #59766: Custom post type archive URLs are being resolved in an unexpected way if a page with the same slug exists and the URL's casing doesn't exactly match the custom post type's rewrite slug

WordPress Trac noreply at wordpress.org
Mon Oct 30 13:34:38 UTC 2023


#59766: Custom post type archive URLs are being resolved in an unexpected way if a
page with the same slug exists and the URL's casing doesn't exactly match
the custom post type's rewrite slug
-------------------------------+-----------------------------
 Reporter:  nonverbla          |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  6.3.2
 Severity:  normal             |   Keywords:  needs-patch
  Focuses:                     |
-------------------------------+-----------------------------
 == Steps to reproduce:

 - Have a custom post type with an archive slug of `/projects/`
 - Have a post with post_type `page` with an identical slug, e.g.
 "Projects", with a slug of "/projects/"
 - Visit "https://example.com/Projects" (note the Titlecase spelling here)
 - Observe how the request is being resolved to the single page "Projects"
 instead of the (expected) post type archive page, even though the rule for
 the post type comes first.

 == Proposed solution

 - I was able to fix this behavior locally by making all archive rewrite
 rules for custom post types case-insensitive. In `class-wp-post-type.php`,
 line #658:

 {{{#!php
 <?php
 // ignore the case of the URL
 $archive_slug = '(?i)' . $archive_slug;
 add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$this->name",
 'top' );
 // ...
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59766>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list