Fix: WordPress Media Library and Attachments Broken After Moving/Cloning Site

I’ve spent countless hours on this problem after it’s happened to three of my clients.  Turns out what has been going wrong, isn’t simply an Automatic Post Thumbnails or Auto Featured Image Plugin, and it’s mostly not simply a difference in Server Configuration (PHP version or whatever)…

For years now, I have made it a point to change my clients’ table prefix from wp_ to something more unique for security purposes, and because it allows me to use the same database which simplifies the process of switching between to versions of a WordPress installation.

I’d duplicate the current site to a subdirectory like /staging/, or whatever, download the database, open the database in a programming text editor, do a find and replace for the domain, replacing all instances so they include the extra directory, then, because it was the perfect opportunity to do so, I’d also do a find and replace to turn all intances of wp_ with xyzabc_ then save the file and import it into the existing database and switch the wp-config.php file in the subdirectory version of the site to use the new xyxabc_ table prefix.

Now I’d have a nice sandbox environment to test out upgrades to the site or any major changes.  Not anymore.  You can no longer simply find-and-replace the table prefix in the database.  I’ve noticed this as of WordPress 3.4.1.  In the past I have only had this problems with sites running Woo themes.


If you found this information helpful, please consider making a donation. No amount is too small.

Bitcoin Donation Address:

3 Replies to “Fix: WordPress Media Library and Attachments Broken After Moving/Cloning Site”

  1. Thanks, just spent 6 hours trying to solve this and your article was the only one that helped solve it. Funny thing is I must have undone everything else that might have caused the issue bar this. Do you recommend a better solution for changing the DB prefix? Thanks again :)

  2. Alex,
    This is something someone definitely needs to build: A plugin that will change the table prefix without screwing anything up.

    I think wp security scan will do it, and I think I’ve successfully done it with that plugin before, but I think there was a delay… a period of time where I thought I had cooked the site and reverted back to the original database in fear… perhaps it just takes a while… Later I notices renamed tables. So I don’t know.

    But a reliable solution for easily updating the table prefix would be awesome. Let me know if you come across one!

  3. I think this is happening with me at the moment. It’s driving me crazy, wondering why the images aren’t showing.

    Yes, just like you. I usually did that find-and-replace through a text editor.

Leave a Reply

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