[wp-trac] [WordPress Trac] #58813: Editing Slug to an Existing Slug causes wrong content to display
WordPress Trac
noreply at wordpress.org
Mon Jul 17 22:13:34 UTC 2023
#58813: Editing Slug to an Existing Slug causes wrong content to display
--------------------------+------------------------------
Reporter: Ipstenu | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by petitphp):
I can reproduce the issue in WordPress 6.2.2 with the classic-editor
plugin, or in WordPress 4.9.18 without the classic-editor.
After a bit of digging, it seems to be caused by two things.
=== Sample permalink in the editor is not accurate
What's displayed in the sample permalink is what the post should end up
using when published. This value is provided by the `sample-permalink`
ajax action.
In reality, the value sent to the server when saving the draft is the
original permalink `post_name`. It can be viewed by enabling the "Slug"
box in the Screen options.
=== Function wp_unique_post_slug doesn't do anything for draft/pending
posts
The function will always [https://github.com/WordPress/wordpress-
develop/blob/trunk/src/wp-includes/post.php#L5020-L5024 return the
original post name for draft posts]. So the duplicate post_name will be
inserted in database while the post is not published.
Ultimately those things combined end up causing the bug you described,
since the WP_Query order results by post_date DESC, the wrong post is
retrieved on front.
This only happen when a user set a custom post_name for a draft post,
that's what trigger the duplicate post_name to be inserted in the
database.
The way they fix it in the block editor is by forcing
`wp_unique_post_slug` to return an actual unique slug in the post rest
controller (post_status is set to "publish" even for draft/pending posts).
------
The most straight-forward way of fixing this bug would be to change the
`wp_unique_post_slug` to always return a unique post_name even for
draft/pending posts.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58813#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list