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
This commit is contained in:
Peter Wilson 2022-04-01 03:25:01 +00:00
parent dc07d3ca67
commit be3aa9a149
2 changed files with 3 additions and 2 deletions

View File

@ -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;

View File

@ -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.