Ticket #3451: 3451.canonical.redirect-pages.diff
File 3451.canonical.redirect-pages.diff, 2.2 KB (added by , 16 years ago) |
---|
-
wp-includes/canonical.php
26 26 27 27 // These tests give us a WP-generated permalink 28 28 if ( is_404() ) { 29 $redirect_url = redirect_guess_404_permalink( );29 $redirect_url = redirect_guess_404_permalink($original); 30 30 } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { 31 31 // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 32 32 if ( is_single() && isset($_GET['p']) ) { … … 157 157 } 158 158 159 159 if ( $redirect_url && $redirect_url != $requested_url ) { 160 // var_dump($redirect_url); die();161 160 $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); 162 161 if ( $do_redirect) { 163 162 // protect against chained redirects … … 175 174 } 176 175 } 177 176 178 function redirect_guess_404_permalink( ) {177 function redirect_guess_404_permalink($original_url) { 179 178 global $wpdb; 180 if ( !get_query_var('name') )181 return false;179 $name = get_query_var('name'); 180 $order = ''; 182 181 183 $where = $wpdb->prepare("post_name LIKE %s", get_query_var('name') . '%'); 182 if ( empty($name) ){ 183 // Check to see if we can pull a postname/page name from the url thats not in the permalink structure 184 //Match string that starts with /, does not contain / and optionally may be followed by / then end of string 185 if( ! preg_match('|\/([^\/.]+)\/?$|', $original_url['path'], $pagemat ) ) 186 return false; 187 $name = $pagemat[1]; 188 $order = "ORDER BY post_parent ASC, post_name ASC"; 189 } 184 190 191 $where = $wpdb->prepare("post_name LIKE %s", $name . '%'); 192 185 193 // if any of year, monthnum, or day are set, use them to refine the query 186 194 if ( get_query_var('year') ) 187 195 $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year')); … … 190 198 if ( get_query_var('day') ) 191 199 $where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day')); 192 200 193 $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish' ");201 $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish' $order LIMIT 1"); 194 202 if ( !$post_id ) 195 203 return false; 196 204 return get_permalink($post_id);