WordPress Workbench - Find replace for DB on cloning

When I clone the Wordpress from boilerplate.originaldomain.com to a new top level domain newdomain.com, many records in the Wordpress database still include https://boilerplate.originaldomain.com, or https:\/\/http://boilerplate.originaldomain.com\ etc… then I will need to fix the db through sql find and replace. Can you include a find / replace in the cloning function to replace any instances of boilerplate.originaldomain.com with the newdomain.com in the sql automatically? This can also be offered as an option, if other users prefer not to find/replace automatically.

I am trying to replace my previous backup / restore solution with WPworkbench, specially using CLI commands for automation. My previous solution does the automatic find/replace and saves me from manual work.

2 Likes

Hello, Kamyar!

Thanks for the heads up!

Yes, I could, but could you explain more about which database fields and in which tables still have the old domain name? And, we do update the wp_options table, and its siteurl, and home—it isn’t a problem for you, right?

Also, do we really need an option, or can we just always perform the replace?

I have a set of preconfigured plugins in the Wordpress that I use as boilerplate. Many of them save the domain name in one way or another. Another place I spotted them are in the custom fields attached to posts and pages, the domain names are not replaced. Another is my theme which saves some of my custom CSS codes in the database. The URL of background images stays as the old domain etc… that is why in general it is helpful to have a complete find and replace, no matter which table.

My previous solutions (Akeeba Backup) does this but asks for confirmation before applying the find/replace which I think is not needed or might make WPworkbench too complicated. I can’t recall clear reasons why when someone clones WP from domain1.com to domain2.com would need to keep some URLs in the database as domain1.com, but there might be cases I am not aware of. So maybe it can be an optional find/replace? or no?

By the way, the other solution also replaces instances of /home/boilerplate.domain.com/ with the new /home/newdomain/ in the whole database.

Is there a case when such replacement wouldn’t be needed? I’m thinking of making it automatic since it’s highly unlikely that the old domain name needs to be preserved upon cloning?

Is the domain home directory also stored in the database?

Is there a case when such replacement wouldn’t be needed? I’m thinking of making it automatic since it’s highly unlikely that the old domain name needs to be preserved upon cloning?

I can’t think of any general case that replacement won’t be needed.

For the home directory, I only found one instance related to the backup plugin that was saved in the database.

I didn’t realize the WP Workbench could let me move my wordpress instance from /wp/ to the root… I’ll need to check it out…

That’s also entirely soluble with a simple rewrite rule in your webserver configuration.

Yes, it can do that as well. Just make sure you have the latest version installed!

I always backup the database and then do a search-and-replace on the href=“…” to transform all links into absolute local links (I wonder why WP doesn’t automatically just keep local links?)
Then only the two entries in the options table that define the site location need to be change.
Is there any down-side to using absolute local links, as long as they reference from the root (href=“/ ----”)?

Can you show me an example of an absolute link vs a relative link? I need to see exactly what you mean.

Hello,

In the Wordpress interface the difference is the following:

What WordPress uses in navigation menus or other internal links looks like this:

Or for pictures:

https://www.mysite.ch/wp-content/uploads/2025/05/Garten-DE.jpg

If you remove the “https://www.mysite.ch” and keep the rest of the url starting with the first slash after the domain name then the links work irrespective of the domain name:

If you export the mysql or MariaDB and do a search-and-replace with a text editor, then you could replace all occurrences of “https://www.mysite.ch/” by “/”
That way all links become local, references the root of the public_html directory. Then re-import the sql file.

So looking at a line in the sql file,

… 25,‘https://www.mysite.ch/wp-content/uploads/2025/05/Garten-DE.jpg’,0,‘attachment’, …

is replaced by this:

… 25,‘/wp-content/uploads/2025/05/Garten-DE.jpg’,0,‘attachment’, …

But the two entries in the WordPress options table for the keys “home” and “siteurl” that define the site root need to be left unchanged, which would normally be the case since they don’t end with a slash, so they don’t get replaced by the search-and-replace:

That’s all right! I’d stick with relative links, but we’ll add an option to automatically replace them when cloning a site.

1 Like

@kamyar.hu Alright, I’ve just added basic find and replace functionality. Now I’m wondering if we need more advanced options like --skip-tables, --skip-columns, --include-columns, or --regex-flags?

Example (with new not yet released WP Workbench Manager):

1 Like

And of course, we’ll use the same API to fix all links when cloning…

1 Like

This looks amazing Ilia. I have rarely needed advanced search and replace options like -skip-tables , --skip-columns , --include-columns , or --regex-flags over years, and in those rare cases a WordPress plugin did the job. So it might be useful for some people at specific moments for sure, but I personally would not consider it as essential (needed).

If the automatic search and replace works during the cloning, replacing old domain with the new one in all the database that would do the job for me.

Thanks!

In this case, I would rather create an advanced section in a collapse. Thanks for the heads up!

I haven’t done it yet, but I will pretty soon.

Unless anyone has better suggestions, it will go like this for search and replace:

There is also --network flag to search/replace through all the tables registered to $wpdb in a multisite install.

And, --all-tables-with-prefix to enable replacement on any tables that match the table prefix even if not registered on $wpdb.

@kamyar.hu Did you ever find those two I left out useful?

Wordpress uses serialise data to store stuff including URLs

  • So if doing manually with text editor = bad
  • you must use wp commands/Apps to make changes.

We will support replacements in serialized data as well.