WordPress Optimized!

More than just another WordPress site

Menu
Skip to content
  • Home
    • Privacy
    • Disclaimer
  • Index
  • Plugin
  • Errors
  • Troubleshooting
  • Security
  • Code Snippet
  • Performance
  • 2BearStudio
  • Posted on January 4, 2016January 5, 2016
  • by Jerry Wang

Troubleshooting: WP redirects to an old post (_wp_old_slug)

This troubleshooting indeed took me a while to even understand why this could happen. The symptom is pretty simple: when trying to access a new post,  you are redirected to another (old) post. Sounds strange, here is how to recreate it.

The Problem

Let’s start with a fresh WordPress installation, where there is only one post called “Hello World”. Now, let’s do some experiment:

  1. Change the title of the post to “Hello WordPress”, also, change the post name (slug) from “hello-world” to “hello-worldpress”.
  2. Open a web browser, access the test site by going to the “Hello WorldPress” post. You will soon find out, the exact same post can be reached via both permalink:
    http://testsite.com/hello-wordpress, and http://testsite.com/hello-world.
  3. Next, let’s create a new post called “Hello World”, and paste some Ipsum dummy content. When we save the post, it should have a post name (slug) “hello-world” assigned by WordPress by default.
  4. Now, if we try to access the new page by going to http://testsite.com/hello-world, it doesn’t bring up the new post just created in step 3. Instead, we are redirected to the old “Hello World” post which has been renamed to “Hello WordPress” at step 1.

After further research, I realized that it is a bug existing in WordPress version 4.4 (or earlier?)., and is reported to be fixed in 4.4.1. Before we can lay our hands on the updated version, let’s fix the problem.

 

The Cause

When renaming a post name (slug) of a post, WordPress records the current post name to a post meta called “_wp_old_slug”. In case user reaches the post by the old slug, WP redirects to the post by reading the _wp_old_slug meta value. It serves the similar purpose like 301 redirect. But the problem is, WP should check existing slug which has higher priority than the “_wp_old_slug”.

If you dig deeper in the database, it looks like this:

wp-post-meta-wp_old_slug

The Fix

The fix is simple, click on the “Delete” button in phpmyadmin. Or for the SQL command:

DELETE FROM wp_postmeta WHERE meta_key=”_wp_old_slug” AND post_id = %id;

remember to replace “wp_postmeta” with your actual database table name, and replace “%id” with the actual value. Or, you can simplify the command to remove all the _wp_old_slug post metas:

DELETE FROM wp_postmeta WHERE meta_key=”_wp_old_slug”;

As for not-so-techy solution, here is a plugin which claims work the wonder.

WordPress Remove Old Slugs

 

Troubleshooting: WP redirects to an old post (_wp_old_slug) was last modified: January 5th, 2016 by Jerry Wang

Related posts:

  1. Take Control of Post Revisions
  2. Restore Custom Post Type from History that doesn’t have Revisions Enabled
  3. Troubleshooting: Archive Link Not Working
  4. List All WordPress Posts by Category
  5. How to Redirect to Post if Search Result Returns Only One Match
Posted in General, TroubleshootingTagged post meta, sql

Post navigation

Prev Batch rename WordPress user_nicename
Next Troubleshooting WordPress: Disable All Plugins?

Recent Posts

  • Make Uncode theme working on your DreamHost shared hosting account
  • Remove /?doing_wp_cron from URL
  • My New iMac Setup Troubleshooting
  • How to Replace Huge Image with Optimized Version the Easy Way
  • How to disable Guternberg Editor – the new Block Editor in WordPress 5
  • How to increase Max Input Vars on DreamHost shared hosting account
  • How to Upgrade to WordPress 5.0 without losing Classic Editor
  • WordPress Security Tip – Avoid using these usernames
The Ultimate Managed Hosting Platform

Recommended WordPress Hosting

Web Hosting  Fastest WordPress Hosting

Coupon & Promotion

  • 10% saving on S2Member Pro (Single-site)
  • 10% saving on S2Member Pro (Unlimited-site)
  • Hostgator 25% off coupon: 25offhosing

WordPress Themes & Plugins

 

Tags

.htaccess 404 500 add_filter() Admin Archive Backup BackWPup Block Editor Coda Cron Custom Post Type DreamHost Email Error Guternberg Hack IfModule Login Membership Menu mobile password Performance PHP Plugin redirect Registration Responsive Revision Search Security Settings SSH Theme Troubleshooting Update WooCommerce wp- WP-CONFIG.PHP wp-login.php wp_query() wp_redirect() WP_TEMP_DIR WSOD

Recommended Plugins

  Gravity Forms Plugin for WordPress   s2Member® (WordPress Membership Plugin)

Categories

  • Code Snippet (30)
  • General (17)
  • Mobile (3)
  • Performance (9)
  • Plugin (23)
  • Security (17)
  • Troubleshooting (29)

Archives

© Copyright 2023 – WordPress Optimized!
Retina Theme by WPAisle ⋅ Powered by WordPress