I copied my WP content to a new install on a different server, so now my uploaded PDF documents have the old URL. Is there a simple way to fix that in all my posts at once, perhaps with SQL or some plugin ?

3 Answers 3


Use the script found here:


Because WordPress serializes some urls in option and meta tables a simple replace won't do.
A siple replace will break your data.
This script will preserve your data and replace it with a new url.
I use it al least twice a month.

  • Worked for me, thx!
    – drake035
    Sep 13, 2012 at 19:46

I have always used the Velvet Blues plugin and it has worked great for me. I couldn't say though how it may or may not handle serialized data. The "easy" factor is pretty hard to beat though.


Go back to the old install. After you exported the SQL database, open it up in any text editor and do a "search and replace", taking your old url and replacing it with your new url. So if I'm going from http://localhost:8888/testsite to http://testsite.com, I need to a search and replace:

  • Search: http://localhost:8888/testsite
  • Replace: http://testsite.com

Make sure you leave off the / at the end as you may miss a few URLs when you do your replacing.

Now just import this new database into the new install.

  • This is a bad way to do it. WordPress serialises some data. If you do this it will break that data.
    – janw
    Sep 13, 2012 at 13:24
  • Sure. Never had an issue doing it this way and I've done it for sites with 1000+ posts/comments etc. so thought I'd mention it.
    – bryceadams
    Sep 13, 2012 at 15:04
  • 1
    This works for the case where you're modifying links in posts, but not if you're trying to modify data that might have been saved by a plugin. Better to use a search/replace plugin to do it.
    – Otto
    Sep 13, 2012 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.