I got it! I ran the WP-CLI command wp search WORKING_SITE.local --network, and I found a couple of entries in wp_26_options::option_value column set to https://WORKING_SITE.local in the siteurl and home opetions (where 26 is the site’s blog_id, which you can find in wp_blogs for example). I then chose another non-working blog ID and checked its wp_X_options table, and found that its options were set to https://NON_WORKING.com. Changing them to .local and rerunning the Sync MultiSite domains to hosts file worked! I can access the site locally, and all page links go to ~.local/page.
(Side note: the redirection turned out to be from browser caching. In Firefox, I went to my history and clicked on the live site, then clicked Forget About This Site. I could then access the .local site without redirection.)
From what I can tell, here’s the process for transferring a live subsite multisite to Local (similar steps to WordPress Multisite with Local - Local):
-
Download a backup of your multisite and its database.
-
Create an empty multisite install on Local and configure the PHP/SQL versions appropriately.
-
If you want to change the WordPress version, open the site shell through Local and run
wp core update --version==X.Y.Z --force. -
Go to your empty site’s directory on your computer (
~/Local Sites/multisite/app/public) and delete thewp-content/folder. Replace it with thewp-content/folder from your backup. -
Drop the
localdatabase tables that were generated while creating the empty multisite. (Either from the terminal in~/public/withwp db clean, or using Adminer.) -
Import the database from your backup. This can be found at
~/wp-content/mysql.sql(Again, either through the terminal withwp db import "PATH"or through Adminer.) -
Change your site’s main domain if necessary (not sure if changing in Local is enough or if https://wpmultisitedomainreplace.com/ is needed, my steps from last week say to use the website first and then change in Local as well. I had set up the multisite with
live-site.com, then used the website to generate the SQL commands (run in Adminer) for changing the database from.comto.local. After that I changed Local’s domain from.comto.local. YMMV.). -
In Adminer, run the SQL command
UPDATE `wp_blogs` SET `domain` = REGEXP_REPLACE(`domain`, '\\.com$', '.local')to update the domains inwp_blogs. This changes the entries in the multisite’s Dashboard > Sites to say.local. -
For each subsite, locate its blog ID (for example, under
blog_idin thewp_blogstable, or in the Sites Dashboard by hovering overEditon a site and looking at the link). Go to thewp_ID_optionstable for the given ID (i.e. if the ID is 5, go towp_5_options) and set thesiteurlandhomeoptions to.local. -
In Local, click on
Sync MultiSite domains to hosts file. You’ll likely be prompted to give Local permission to edit your hosts file. Afterwards, you can access your subsite locally!
A couple of caveats:
-
I’ve not explored automating step 9 yet (that’s next for me). There’s also
wp search-replace --network, but I don’t know if that would change too much and cause unforeseen problems. Still need to test. -
I’ve also not been able to get SSL to work for any of the sites, whether it’s the main domain or any of the subsites. Perhaps Generate SSL for multiple local domains within a multisite (domain or subdomain) - #2 by ben.turner?
-
I had an issue where I could access the Dashboard for my main domain, but not a subsite. At first, the issue came from a WP Engine plugin - removing the
wp-content/mu-plugins/folder fixed the error message preventing me from logging in (settingWP_DEBUGtofalseinwp-config.phpalso helped). However, when I went to login, I got the errorCookies are blocked or not supported by your browser. You must enable cookies to use WordPress.preventing me from logging in. Inwp-config.php, addingdefine( 'COOKIE_DOMAIN', false );fixed it and let me log in. Don’t know how that would affect the live site if pushed to production, though.
Happy editing!