Opened 12 months ago
Last modified 2 months ago
#52422 new defect (bug)
Create a draft with the same slug as an existing post, the existing post will be 404.
Reported by: | Toro_Unit | Owned by: | |
---|---|---|---|
Milestone: | 6.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests needs-refresh has-testing-info needs-testing |
Focuses: | Cc: |
Description
Step-by-step reproduction instructions
- create custom post type. and set
'show_in_rest' => true
<?php function custom_init() { $args = array( 'public' => true, 'label' => 'Books', 'show_in_rest' => true, ); register_post_type( 'book', $args ); } add_action( 'init', 'custom_init' );
- Publish new post of the post type.
- Create draft post of the post type with same slug.
- Go to the published post. but show draft post. if logged out, 404.
Using the block editor, a page can also create drafts with the same slug, which causes the same problem.
Attachments (2)
Change History (11)
#2
@
12 months ago
I've attempted to reproduce this on both 5.6 and trunk without success. I've tried with both a CPT per the original post and standard posts per the follow up comment.
Are either of you able to reproduce this with all plugins disabled and using a default theme such as Twenty Twenty-One?
#3
@
12 months ago
@peterwilsoncc Thanks.
No plugins are used, and the theme is Twenty Twenty One. reproduced on WordPress 5.5 and 5.6.
When creating a post, please use the block editor.
Quick Edit or Classic Editor don't allow us to create a post with the same slug as an existing post.
This ticket was mentioned in PR #1333 on WordPress/wordpress-develop by torounit.
8 months ago
- Keywords has-patch has-unit-tests added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/52422.
Using the block editor, a draft can have the same slug as a post that already exists.
There is a part in WP_Query that uses get_page_by_path, so it may load the wrong post.
A hack similar to wp_ajax_inline_save, fixed so that the slug is different.
#6
@
7 months ago
get_page_by_path is used in WP_Query.
- Draft page ( id: 1, slug: foo, status: draft )
- Published page ( id: 2, slug: foo, status: publish )
If the above two posts exist, get_page_by_path will get the draft page. That post will be set to queried_object.
https://github.com/WordPress/wordpress-develop/blob/5.7.2/src/wp-includes/class-wp-query.php#L1001
#9
@
2 months ago
- Keywords needs-refresh has-testing-info needs-testing added
- Milestone changed from 5.9 to 6.0
Updating the keywords:
- Marking as
needs-refresh
as there are merge conflicts - Marking as
has-testing-info
as there are step-by-step instructions - Marking as
needs-testing
as I too am unable to reproduce the reported problem
I'm not able to reproduce this problem either. It needs more investigation. As 5.9 Beta 1 is in 2 days, moving it to 6.0.
It also happened in default posts.
%postname%
.