Opened 10 years ago
Closed 10 years ago
#30339 closed defect (bug) (fixed)
Infinite loop while checking for post slug uniqueness
Reported by: | julien731 | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | major | Version: | 4.1 |
Component: | Posts, Post Types | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
When inserting a new hierarchical post of any type using wp_insert_post()
, the wp_unique_post_slug()
function creates an infinite loop when checking for already existing posts with the same slug.
In wp_unique_post_slug()
, when entering the case of is_post_type_hierarchical()
(line 3698 in the trunk as of today), the query is missing the $post_type
variable when being prepared. The query set in $check_sql
contains 4 parameters but only 3 are given in $wpdb->prepare()
(line 3723) while looping in the post slugs.
As a result, $wpdb->prepare()
returns false
because of the last argument (post_parent
) not being given, and no SQL query is run at all. $wpdb->get_var()
then returns the last cached result.
Attachments (1)
Change History (9)
This ticket was mentioned in Slack in #core by julien731. View the logs.
10 years ago
#2
@
10 years ago
- Keywords needs-testing added
It looks like the issue was created with revision r30158.
#4
@
10 years ago
- Keywords needs-unit-tests added; needs-testing removed
We need a unit test which covers the situation where some-slug
and some-slug-2
already exist, so the code steps into the while
loop.
#5
@
10 years ago
I've re-opened the original ticket #18962 with another issue, I've uploaded patch which also contains the fix for this ticket from @julien731 and a unit test for it.
Patched version of post.php with $post_type added to the query