WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#28017 new defect (bug)

Slug conflict with hierarchical Custom Post Types

Reported by: internetrnd Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9
Component: Posts, Post Types Keywords: needs-patch
Focuses: Cc:
PR Number:

Description

To Replicate, create a hierarchical custom post type and make sure it has support for page attributes, lets call it "items"

Publish 3 "items" posts with the following slug and content ( IN THIS ORDER! )

Post 1: Slug - samsung , No Parent , content : "Welcome to Samsung"
Post 2: Slug - cell-phones , No Parent , content : "Welcome to cell phones"
Post 3: Slug - samsung , Parent: cell-phones , content : "Welcome to cell phones by Samsung"

Navigate to http://localhost/items/samsung/ , You will see the content for Post 3. The correct content should be from Post 1. http://localhost/items/cell-phones/samsung/ works just fine.

To get the correct results:

Modify wp-includes/query.php , line 2340:

// ORIGINAL LINE
if ( ! $ptype_obj->hierarchical || strpos($q[ $ptype_obj->query_var ], '/') === false ) {

// MODIFIED LINE
if ( ! $ptype_obj->hierarchical ) { 


Attachments (1)

wp-3-9.patch (816 bytes) - added by internetrnd 4 years ago.
Patch for 3.9 branch

Download all attachments as: .zip

Change History (5)

#1 follow-up: @jesin
5 years ago

I was able to reproduce this problem, but for me navigating to /items/samsung/ displayed both Post 1 and Post 3 on the same page.

Also I find that disabling permalinks sets the link of both Post 1 and 3 to /?items=samsung and accessing this link displays both of them.

#2 in reply to: ↑ 1 @internetrnd
5 years ago

Try changing the post type capability_type to "page"

#3 @chriscct7
4 years ago

  • Keywords needs-patch added

@internetrnd
4 years ago

Patch for 3.9 branch

#4 @internetrnd
4 years ago

Patch has been attached. It looks like the fix I mentioned in the original 2014 post was applied to the 4.x branch. Was there a separate bug report submitted to that branch?

Note: See TracTickets for help on using tickets.