Table of Contents
Copy wordpress multisite site (theme) to another site
Wordpress saves the different sites inside
wp-content/uploads/sites/3/. There are corresponding wp tables in the database e.g.
| wp_3_actionscheduler_actions | | wp_3_actionscheduler_claims | | wp_3_actionscheduler_groups | | wp_3_actionscheduler_logs | | wp_3_commentmeta | | wp_3_comments | | wp_3_links | | wp_3_options | | wp_3_postmeta | | wp_3_posts | | wp_3_term_relationships ...
Copy the required themes and plugins from main site
Example copying astra and astra-child theme to site number 3 (check wp admin for number).
cp -r wp-content/themes/astra* wp-content/uploads/sites/3/
Copying elementor plugin as well
cp -r wp-content/uploads/elementor wp-content/uploads/sites/3/
Also copy any images or other files that are uploaded in e.g. wp-content/uploads/sites/3/2021 folders.
Update the database tables
Dump the database first:
mysqldump -uroot -p sitedb > sitedb_bak.sql
Cut out only the main site tables which we will use for import later:
sed -n -e '/DROP TABLE.*`wp_[a-zA-Z].*`/,/UNLOCK TABLES/p' sitedb_bak.sql > wp_main_site.sql
Open the file with vim and search and replace table names with correct prefix, e.g we want to overwrite settings in site numbered 3 in DB so we are renaming the table names to
vi wp_main_site.sql :%s/wp_\(.*\)/wp_3_\1/g
So a statement like
INSERT INTO `wp_postmeta` VALUES ...
INSERT INTO `wp_3_postmeta` VALUES ...
Substitute URLs as well
Import and overwrite tables in DB
mysql -uroot -p sitedb < wp_main_site.sql
Refresh the page and regenerate CSS from WP admin theme settings or plugin, depending on what is being used.
- Debian 10.7
- Wordpress 5.6
- Elementor v3.0.16