• Thu. Dec 9th, 2021

php – 404 on old link after changing post url

Byadmin

Oct 18, 2021


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 happends in cases like the example bellow
if original post link abc.com/how-to-example
if i change to abc.com/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



source

Leave a Reply

Your email address will not be published. Required fields are marked *