admin管理员组

文章数量:1279050

Hello I have a problem where i have 404 on posts after changing url with php using this function

wp_update_post( array(
                    'ID' => $post_id,
                    'post_name' => $new_slug
                ));

This happens in cases like the example below

if original post link abc/how-to-example
if I change to abc/how-to-example-passwd <-- redirect will still work
and I change again to a new permalink for third time redirect will work only for original link and new link and changes made between those two will return 404

Is it possible to keep all changes and make them redirect to current post using php?
I noticed wp automatically keep a custom field for the original link only

Hello I have a problem where i have 404 on posts after changing url with php using this function

wp_update_post( array(
                    'ID' => $post_id,
                    'post_name' => $new_slug
                ));

This happens in cases like the example below

if original post link abc/how-to-example
if I change to abc/how-to-example-passwd <-- redirect will still work
and I change again to a new permalink for third time redirect will work only for original link and new link and changes made between those two will return 404

Is it possible to keep all changes and make them redirect to current post using php?
I noticed wp automatically keep a custom field for the original link only

Share Improve this question edited Oct 19, 2021 at 9:30 Rup 4,4004 gold badges29 silver badges29 bronze badges asked Oct 18, 2021 at 5:11 Monkey LuffyMonkey Luffy 1 1
  • Why are you doing this? This appears to be a terrible idea. – vancoder Commented Oct 18, 2021 at 15:39
Add a comment  | 

1 Answer 1

Reset to default 0

You will need to add the following code in your htaccess.

Redirect 301 <Old Url> <New Url>

Place old link of your post in place of <Old Url> and new link in place of <New Url>

For reference view this link.

本文标签: php404 on old link after changing post url