Support » Fixing WordPress » Successfully changed server. Need to update links in my posts

  • benducklow


    Hello, I’ve been using WordPress for almost a year and love it. My first and most difficult move took place and it went fairly smooth; I moved my install from one server to another.

    Everything is working except I’ve run into an issue with links to pictures in my posts. They are all linking back to the old site url; therefore the image link is broken. Is there a way to do some sort of mass change I can do to change the url for the image to my new url? I use WP 2.04 w/ MySQL/PHPMyAdmin.

    Hopefully you know what I am trying to say. Thanks in advance for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    There’s two ways to do it.

    1) Create a plugin to automagically replace your old site URL with the new site. This is not difficult, but it doesn’t change the actual content of the posts, just what is displayed.

    This would work something like this:
    function fix_post_URLs($text) {
    return str_replace("OLDURL","NEWURL",$text);
    add_filter('the_content', 'fix_post_URLs');
    add_filter('the_content_rss', 'fix_post_URLs');
    add_filter('the_excerpt', 'fix_post_URLs');
    add_filter('the_excerpt_rss', 'fix_post_URLs');

    2) Actually change the database to reflect the new changes.

    This is not as difficult as it sounds. If you have phpMyAdmin, it’s simple.

    a. Make a full database backup. Always make a database backup when you’re modifying things en masse. You can use the wp-backup plugin that comes with wordpress to do this.

    b. Open that backup file. You’ll find that it’s a series of SQL statements which basically restore your posts and other bits. Find the wp_posts section. Cut and paste it into a new text file (don’t modify the backup itself!)

    c. Use a Search/Replace to change all the bits with your old URL to have your new one.

    d. Using phpMyAdmin, delete the wp_posts rows out of your database and reinsert them from your modified insertion SQL statement.

    If you don’t know databases and SQL, I do not recommend the latter approach. However, if you do know databases and SQL, you’ll find this extremely easy to do.

    Oh, and then there’s always 3) Manually edit each post.



    Thanks Otto42 I actually did start doing the 3rd option but found it was way to tedious. I am not that familiar with MySql but do think I could accomplish this (I know some database stuff). My only question at this point is what to open/edit the backed up database in. I have the backed up files already downloaded to my hard drive.

    Thanks and another other info would be appreciated!

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    My only question at this point is what to open/edit the backed up database in.

    Notepad? Any text editor will do.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Successfully changed server. Need to update links in my posts’ is closed to new replies.