Opened 5 weeks ago
Last modified 4 weeks ago
#61824 new defect (bug)
Pages no longer allowed to have same permalink as images
Reported by: | thommo | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.6.1 |
Component: | Permalinks | Keywords: | needs-patch |
Focuses: | Cc: |
Description
In an existing website, if I have an image called sausages and I also already have a page called sausages, I get a 404 when attempting to visit the page. In addition, when looking at the page in the backend, it says the permalink will become sausages-2 when it is updated. I don't know but I wonder whether this is caused by both rows in wp_posts having a post_name of sausages. Previously this has not been an issue as the actual URL for the image would have wp-content/uploads/2024/08 (or similar added to it). Deleting the image results in the page working again (without the "-2").
Change History (4)
#2
in reply to:
↑ 1
@
5 weeks ago
Hi Sabernhardt,
I think you are right, I think it is related. I may be wrong but it looks to me as if patch 60941.diff (https://core.trac.wordpress.org/attachment/ticket/13459/60941.diff) mentioned in #13459 and added 2 weeks ago "Patched to resolve duplicate post and page slug issues. Now, it will add '-2' if the post or page slug already exists." may have fixed the problem in #13459 but introduced this new problem by mistake.
#3
follow-up:
↓ 4
@
4 weeks ago
It's been the case for a while that attachments and pages can't share the same post slug. The reason being that they can share the same URL space.
If you upload the file sausages.jpg directly to the post library, the attachment page will be given the URL example.com/sausages. If you subsequently create the page Sausages, it too will have the URL example.com/sausages.
The second page or attachment to be created should have the slug sausages-2
.
Did you end up in a situation in which the two items both had the same slug? I tried reproducing it by uploading an attachment and then creating a page of the same name but was unable to.
#4
in reply to:
↑ 3
@
4 weeks ago
Hi Peter,
Yes, you're right, adding a new image and creating a new page now works exactly as you say.
The problem is that the site has been live for a long time. In the database, the post_name for the media and page in the posts table were identical. Previously, the site displayed the page when going to the url (this may be because attachment pages are disabled using the Yoast plugin?). We had no issues when updating the page (it allowed the post_name to remain as it was and the page displayed as expected).
However, after applying the latest version of WP, going to the URL gave a 404. And, when we open the page to edit it in the backend, the permalink has been altered to add "-2" to the end of it. If we update it, it changes the URL for the page which causes a lot of links to break.
For us, for the two pages affected on this site, we could delete the old media files as they were no longer used and the pages worked again.
What I don't know is whether Yoast played a part in making the site work previously and that, if Yoast had not been there, maybe something different would have happened.
Hi and thanks for the report!
#13459 is related, though this might not be an exact duplicate of that.