Make WordPress Core


Ignore:
Timestamp:
06/09/2020 07:24:23 PM (5 years ago)
Author:
whyisjake
Message:

Canonical: Ensure a redirect for posts missing postname in a query with an ID.

If a site is using /%post_id%/%postname%/ as permalink structure, and is missing the postname, the site won't redirect to the appropriate URL. This change ensure that the redirect happens.

Fixes: #12456.
Props: Frank.Prendergast, dd32, Otto42, hlanggo, wonderboymusic, atimmer, seth17, calvin_ngan, Niresh12495, anbumz, SergeyBiryukov, donmhico.

File:
1 edited

Legend:

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

    r47885 r47937  
    410410
    411411            $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     412        } elseif ( is_singular() && empty( get_query_var( 'name' ) ) && $post_id ) {
     413            /*
     414             * Redirect example.org/%post_id%/ to canonical url.
     415             * @ticket 12456
     416             */
     417            $redirect_url      = get_permalink( $post_id );
     418            $redirect['query'] = _remove_qs_args_if_not_in_url(
     419                $redirect['query'],
     420                array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ),
     421                $redirect_url
     422            );
    412423        }
    413424
Note: See TracChangeset for help on using the changeset viewer.