Make WordPress Core


Ignore:
Timestamp:
04/01/2022 03:23:07 AM (2 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r52833 r53043  
    958958        }
    959959
     960        $publicly_viewable_statuses = array_filter( get_post_stati(), 'is_post_status_viewable' );
    960961        // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
    961         $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" );
     962        $post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status IN ('" . implode( "', '", esc_sql( $publicly_viewable_statuses ) ) . "')" );
    962963
    963964        if ( ! $post_id ) {
Note: See TracChangeset for help on using the changeset viewer.