summaryrefslogtreecommitdiffstats
path: root/wp-includes/query.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-11-30 18:54:22 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-11-30 18:54:22 +0000
commit9415bbca12c01c39da58e0ed2c4e6b44ff833e5d (patch)
tree72e6c3da0cf5b18f808b7b5002ffd41f3edc0904 /wp-includes/query.php
parent475ef251608d4d8a4d44a86d99693c416a1159fd (diff)
downloadwordpress-mu-9415bbca12c01c39da58e0ed2c4e6b44ff833e5d.tar.gz
wordpress-mu-9415bbca12c01c39da58e0ed2c4e6b44ff833e5d.tar.xz
wordpress-mu-9415bbca12c01c39da58e0ed2c4e6b44ff833e5d.zip
WP Merge to 4559
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@816 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-includes/query.php')
-rw-r--r--wp-includes/query.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/wp-includes/query.php b/wp-includes/query.php
index 6f5fbf0..337e149 100644
--- a/wp-includes/query.php
+++ b/wp-includes/query.php
@@ -1116,6 +1116,40 @@ class WP_Query {
}
}
+
+// Redirect old slugs
+function wp_old_slug_redirect () {
+ global $wp_query;
+ if ( is_404() && '' != $wp_query->query_vars['name'] ) :
+ global $wpdb;
+
+ $query = "SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND meta_key = '_wp_old_slug' AND meta_value='" . $wp_query->query_vars['name'] . "'";
+
+ // if year, monthnum, or day have been specified, make our query more precise
+ // just in case there are multiple identical _wp_old_slug values
+ if ( '' != $wp_query->query_vars['year'] )
+ $query .= " AND YEAR(post_date) = '{$wp_query->query_vars['year']}'";
+ if ( '' != $wp_query->query_vars['monthnum'] )
+ $query .= " AND MONTH(post_date) = '{$wp_query->query_vars['monthnum']}'";
+ if ( '' != $wp_query->query_vars['day'] )
+ $query .= " AND DAYOFMONTH(post_date) = '{$wp_query->query_vars['day']}'";
+
+ $id = (int) $wpdb->get_var($query);
+
+ if ( !$id )
+ return;
+
+ $link = get_permalink($id);
+
+ if ( !$link )
+ return;
+
+ wp_redirect($link, '301'); // Permanent redirect
+ exit;
+ endif;
+}
+
+
//
// Private helper functions
//