Make WordPress Core

Ticket #19693: 19693.diff

File 19693.diff, 1000 bytes (added by jeremyfelt, 13 years ago)

Adds stricter post_type query to redirect_guess_404_permalink

  • canonical.php

     
    476476        if ( get_query_var('name') ) {
    477477                $where = $wpdb->prepare("post_name LIKE %s", like_escape( get_query_var('name') ) . '%');
    478478
    479                 // if any of post_type, year, monthnum, or day are set, use them to refine the query
     479                // Use either an explicitly set post_type or search IN all registered and publicly queryable post types
    480480                if ( get_query_var('post_type') )
    481481                        $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type'));
     482                else
     483                        $where .= $wpdb->prepare(" AND post_type IN ('" . implode( "', '", get_post_types( array( 'publicly_queryable' => true ) ) ) . "')" );
     484
     485                // if any of year, monthnum, or day are set, use them to refine the query
    482486                if ( get_query_var('year') )
    483487                        $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year'));
    484488                if ( get_query_var('monthnum') )