WordPress.org

Make WordPress Core

Ticket #16949: 16949.2.diff

File 16949.2.diff, 1.6 KB (added by aaroncampbell, 7 years ago)

Allow wp_old_slug_redirect() to handle multiple post types

  • wp-includes/query.php

     
    34893489                if ( get_query_var('post_type') )
    34903490                        $post_type = get_query_var('post_type');
    34913491                elseif ( !empty($wp_query->query_vars['pagename']) )
    3492                         $post_type = 'page';
     3492                        $post_type = array( 'page' );
    34933493                else
    3494                         $post_type = 'post';
     3494                        $post_type = array( 'post' );
    34953495
    3496                 // Do not attempt redirect for hierarchical post types
    3497                 if ( is_post_type_hierarchical( $post_type ) )
     3496                if ( ! is_array( $post_type ) ) {
     3497                        $post_type = preg_split( '/\s+,\s+/', $post_type );
     3498                }
     3499
     3500                $post_type_query = array();
     3501                foreach ( $post_type as $pt ) {
     3502                        // Do not attempt redirect for hierarchical post types
     3503                        if ( !is_post_type_hierarchical( $pt ) )
     3504                                $post_type_query[] = $wpdb->prepare( 'post_type = %s', $pt );
     3505                }
     3506
     3507                if ( empty( $post_type_query ) )
    34983508                        return;
    34993509
    3500                 $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']);
     3510                $post_type_query = '( ' . implode( ' OR ', $post_type_query ) . ' )';
    35013511
     3512                $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND {$post_type_query} AND meta_key = '_wp_old_slug' AND meta_value = %s", $wp_query->query_vars['name']);
     3513
    35023514                // if year, monthnum, or day have been specified, make our query more precise
    35033515                // just in case there are multiple identical _wp_old_slug values
    35043516                if ( '' != $wp_query->query_vars['year'] )