Changeset 38463
- Timestamp:
- 08/31/2016 06:20:03 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r38351 r38463 845 845 * @since 2.1.0 846 846 * 847 * @global WP_Query $wp_query Global WP_Query instance. 848 * @global wpdb $wpdb WordPress database abstraction object. 847 * @global wpdb $wpdb WordPress database abstraction object. 849 848 */ 850 849 function wp_old_slug_redirect() { 851 global $wp_query; 852 853 if ( is_404() && '' !== $wp_query->query_vars['name'] ) : 850 if ( is_404() && '' !== get_query_var( 'name' ) ) { 854 851 global $wpdb; 855 852 … … 859 856 } elseif ( get_query_var( 'attachment' ) ) { 860 857 $post_type = 'attachment'; 861 } elseif ( ! empty( $wp_query->query_vars['pagename']) ) {858 } elseif ( get_query_var( 'pagename' ) ) { 862 859 $post_type = 'page'; 863 860 } else { … … 866 863 867 864 if ( is_array( $post_type ) ) { 868 if ( count( $post_type ) > 1 ) 865 if ( count( $post_type ) > 1 ) { 869 866 return; 867 } 870 868 $post_type = reset( $post_type ); 871 869 } 872 870 873 871 // Do not attempt redirect for hierarchical post types 874 if ( is_post_type_hierarchical( $post_type ) ) 872 if ( is_post_type_hierarchical( $post_type ) ) { 875 873 return; 876 877 $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']); 874 } 875 876 $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, get_query_var( 'name' ) ); 878 877 879 878 // if year, monthnum, or day have been specified, make our query more precise 880 879 // just in case there are multiple identical _wp_old_slug values 881 if ( '' != $wp_query->query_vars['year'] ) 882 $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']); 883 if ( '' != $wp_query->query_vars['monthnum'] ) 884 $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']); 885 if ( '' != $wp_query->query_vars['day'] ) 886 $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']); 887 888 $id = (int) $wpdb->get_var($query); 889 890 if ( ! $id ) 880 if ( get_query_var( 'year' ) ) { 881 $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var( 'year' ) ); 882 } 883 if ( get_query_var( 'monthnum' ) ) { 884 $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var( 'monthnum' ) ); 885 } 886 if ( get_query_var( 'day' ) ) { 887 $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var( 'day' ) ); 888 } 889 890 $id = (int) $wpdb->get_var( $query ); 891 892 if ( ! $id ) { 891 893 return; 894 } 892 895 893 896 $link = get_permalink( $id ); 894 897 895 if ( isset( $GLOBALS['wp_query']->query_vars['paged'] ) && $GLOBALS['wp_query']->query_vars['paged']> 1 ) {896 $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . $GLOBALS['wp_query']->query_vars['paged']);898 if ( get_query_var( 'paged' ) > 1 ) { 899 $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) ); 897 900 } elseif( is_embed() ) { 898 901 $link = user_trailingslashit( trailingslashit( $link ) . 'embed' ); … … 914 917 wp_redirect( $link, 301 ); // Permanent redirect 915 918 exit; 916 endif;919 } 917 920 } 918 921
Note: See TracChangeset
for help on using the changeset viewer.