Merge Multisites with Shared Network Media Library


So have a multisite setup which no longer needs to be a multisite but I’m left with a bit of a mess since I used Network Media Library plugin to host images for all sites on the network. I’ll try to break it down:

  • started out with WP multisite
  • created two sites on the network
  • installed Network Media Library
  • site #1 hosted the media library
  • both sites hosted posts
  • (about a year and a lot of posting goes by)
  • pulled site #1 out of multisite to be hosted independently
  • left with multisite running site #2 but still pulling it’s media from site #1

What I want to do now is combine site #2 which contains all my posts with site #1 which contains only media. My concerns are:

  • if I merge tables there will be ID conflicts (some posts will have same ID as attachments)
  • if I use import function to bring images into posts site then images will be given new IDs and post thumbnail relations will all break
  • if I use import function to bring posts into images site then post IDs would change which can’t happen because we use the ID in the post URL

The best idea I have so far is to somehow…

  • use the WordPress import function to import all the attachments into the posts site
  • log old and new IDs into a new table in the DB as the process works
  • then iterate over all the posts switching old for new IDs in the post_meta _thumbnail_id fields
  • ideally then be left with one site which contains all the posts and attachments so I can reduce the install down to regular non-multisite.

There’s tens of thousands of posts on these combined sites so performing these functions is no small feat and really not sure where to start so I wonder if anyone has any experience of a process like this or ideas for alternative solutions.

Thanks for reading.