From be3aa9a149cc361f8189e2a3f7555cc81878ba90 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Fri, 1 Apr 2022 03:25:01 +0000 Subject: [PATCH] Canonical: Include all public status in 404 redirects. In `redirect_guess_404_permalink()` search for posts using all publicly queryable statuses rather than limiting options to the `publish` status. Props goaroundagain, costdev, htdat, audrasjb, chaion07. Fixes #47911. Built from https://develop.svn.wordpress.org/trunk@53043 git-svn-id: http://core.svn.wordpress.org/trunk@52632 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 3 ++- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 0defa8227d..9404ed6ea5 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -957,8 +957,9 @@ function redirect_guess_404_permalink() { $where .= $wpdb->prepare( ' AND DAYOFMONTH(post_date) = %d', get_query_var( 'day' ) ); } + $publicly_viewable_statuses = array_filter( get_post_stati(), 'is_post_status_viewable' ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared - $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" ); + $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", esc_sql( $publicly_viewable_statuses ) ) . "')" ); if ( ! $post_id ) { return false; diff --git a/wp-includes/version.php b/wp-includes/version.php index 66720e0022..eea44f30e2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-53042'; +$wp_version = '6.0-alpha-53043'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.