#15665 closed defect (bug) (fixed)
Page name won't work if the parent page has an attachment with the same name
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | high | Milestone: | 3.5 |
| Component: | Permalinks | Version: | 3.1 |
| Severity: | normal | Keywords: | has-patch needs-testing early |
| Cc: | westi, ipstenu@… |
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 (30)
designsimply
— 3 years ago
comment:2
scribu
— 3 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.
comment:3
follow-up:
↓ 10
westi
— 3 years ago
I suspect the real fix here is to find out why we match attachment slugs when looking up root level pages
comment:5
designsimply
— 3 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
comment:6
garyc40
— 2 years ago
- Keywords has-patch needs-testing 3.2-early added; needs-patch removed
comment:7
garyc40
— 2 years ago
Can't reproduce your problem with author and category though. More detailed steps?
comment:10
in reply to:
↑ 3
;
follow-up:
↓ 11
duck_
— 18 months 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.
comment:11
in reply to:
↑ 10
duck_
— 18 months 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.
comment:12
SergeyBiryukov
— 14 months ago
Closed #20612 as a duplicate.
comment:13
Viper007Bond
— 13 months ago
- Component changed from General to Permalinks
- Priority changed from normal to high
This is super annoying. We should resolve this.
comment:14
SergeyBiryukov
— 12 months ago
Closed #21008 as a duplicate.
SergeyBiryukov
— 12 months ago
comment:16
SergeyBiryukov
— 12 months 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.
devesine
— 12 months ago
Here's a unit test which tests this bug. Comments gratefully accepted - particularly as this is the first WP test I've written.
comment:18
devesine
— 12 months ago
15665-unit.patch executes the reproduction steps described in the bug; currently fails, passes with patch applied.
comment:19
trepmal
— 12 months 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.
comment:20
follow-up:
↓ 21
nacin
— 12 months 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.
comment:21
in reply to:
↑ 20
devesine
— 12 months ago
Replying to nacin:
simply call wp_insert_attachment()
Looks like that works fine; updated in 15665-unit-2.patch.
comment:22
SergeyBiryukov
— 11 months ago
Closed #21216 as a duplicate.
comment:23
SergeyBiryukov
— 11 months ago
Closed #21501 as a duplicate.
comment:24
nacin
— 9 months ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In [21845]:
comment:25
nacin
— 9 months ago
- Keywords needs-unit-tests removed
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. :)