#15665 closed defect (bug) (fixed)
Page name won't work if the parent page has an attachment with the same name
Reported by: | designsimply | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.5 | Priority: | high |
Severity: | normal | Version: | 3.1 |
Component: | Permalinks | Keywords: | has-patch needs-testing early |
Focuses: | Cc: |
Description
It's possible to create a page name that has the same name as an attachment page with the same parent. If you do that, the attachment page takes precedent and it's not possible to display the page with the matching name.
To reproduce:
- Create a page, attach some images to it, save and publish
- Create a child page with the same name as one of images attached to the parent page
---> Result: a page name and an attachment page name that are the same and it's not possible to view the page at http://example.com/parent_page_name/page_name/
Tested with r16708
Making the attachment post type hierarchical fixes it this my tests. Is there any reason attachment post types should not be hierarchical?
Attachments (5)
Change History (34)
#2
@
14 years ago
- Keywords needs-patch added; has-patch needs-testing removed
- Milestone changed from Awaiting Review to Future Release
Making the attachment post type hierarchical fixes it this my tests. Is there any reason attachment post types should not be hierarchical?
Yes, attachments are not hierarchical because it doesn't make sense to link an attachment to another attachment.
We should find a better way to fix this.
#3
follow-up:
↓ 10
@
14 years ago
I suspect the real fix here is to find out why we match attachment slugs when looking up root level pages
#5
@
14 years ago
Found two additional cases where it's possible to add pages that conflict with auto-generated pages:
- author/EXISTING_BLOG_USER
- category/EXISTING_CATEGORY
This is in addition to the case originally reported where it's possible to add a page that conflicts with existing attachment pages names for the same parent page:
- PARENT_PAGE/ATTACHMENT_PAGE
#7
@
14 years ago
Can't reproduce your problem with author
and category
though. More detailed steps?
#10
in reply to:
↑ 3
;
follow-up:
↓ 11
@
13 years ago
#19683 was closed as a duplicate, apparently root level pages were not susceptible to collisions prior to 3.3. This is might due to changes in get_page_by_path(), see #16687.
Replying to westi:
I suspect the real fix here is to find out why we match attachment slugs when looking up root level pages
get_page_by_path() queries for attachment as well as the specified post type.
Related #17170.
#11
in reply to:
↑ 10
@
13 years ago
Replying to duck_:
apparently root level pages were not susceptible to collisions prior to 3.3.
Sorry for repeating that without double checking. It's wrong.
#13
@
12 years ago
- Component changed from General to Permalinks
- Priority changed from normal to high
This is super annoying. We should resolve this.
#16
@
12 years ago
- Keywords early added; 3.2-early needs-refresh removed
- Milestone changed from Future Release to 3.5
15665.patch compares found post type with the requested one before breaking the loop, to see if we can find an item that meets all other requirements and also has the same post type.
@
12 years ago
Here's a unit test which tests this bug. Comments gratefully accepted - particularly as this is the first WP test I've written.
#18
@
12 years ago
15665-unit.patch executes the reproduction steps described in the bug; currently fails, passes with patch applied.
#19
@
12 years ago
Just came across a little issue which I believe is related to this.
If I have a page "Rooms," for example, with child page "Amenities" as well as a CPT with 'rooms' as the rewrite slug (below), the child page /rooms/amenties/
will 404 as 'amenties' is expected to be part of the CPT
register_post_type('room', array( //... 'rewrite' => array('slug' => 'rooms') //... ));
If unrelated, let me know, I'll check again for an existing ticket or open a new one.
#20
follow-up:
↓ 21
@
12 years ago
I think we can simply call wp_insert_attachment() rather than actually upload a file for 15665-unit.patch.
trepmal, that does not appear related.
#21
in reply to:
↑ 20
@
12 years ago
Replying to nacin:
simply call wp_insert_attachment()
Looks like that works fine; updated in 15665-unit-2.patch.
#24
@
12 years ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In [21845]:
This ticket was mentioned in IRC in #wordpress-dev by SergeyBiryukov. View the logs.
11 years ago
#28
follow-up:
↓ 29
@
11 years ago
The same problem occurs with posts if you're using the popular /%postname%/
permalink structure. If you upload an image and then create a post that gets the same slug as the image (different post type, so there is no collision protection here), the front end will display the attachment rather than the post at site.com/some-shared-slug
#29
in reply to:
↑ 28
@
11 years ago
Replying to aaroncampbell:
The same problem occurs with posts if you're using the popular
/%postname%/
permalink structure. If you upload an image and then create a post that gets the same slug as the image (different post type, so there is no collision protection here), the front end will display the attachment rather than the post at site.com/some-shared-slug
Thanks, I've reopened #24612 (which I thought was a duplicate, but this ticket only covered pages). See also #13459.
This is definitely duplicating another ticket somewhere. But I think this is the first time I've seen it well-explained and with a patch. :)