Migrating Wordpress with divi or elementor - json

I use this commands to migrate in the old day, but with divi or elementor, some crash with migration, anyone use other way ? other idea ? It's due to Json ?
UPDATE wp_options
SET option_value = replace(option_value, 'http://www.old-site.com', 'https://www.new-site.com')
WHERE option_name = 'home'
OR option_name = 'siteurl';
UPDATE wp_posts
SET guid = REPLACE (guid, 'http://www.old-site.com', 'https://www.new-site');
UPDATE wp_posts
SET post_content = REPLACE (post_content, 'https://www.old-site.com', 'https://www.new-site.com');
UPDATE wp_postmeta
SET meta_value = REPLACE (meta_value, 'http://www.old-site.com','https://www.new-site.com');
Thanks

You shouldn't change the guid as that will cause RSS readers to think that all of the posts are now new unread posts.
You might be missing some stuff to replace. Typically when migrating to the new site you do the find and replace on everything in the database (except for the guid). There are some tools that can help you out with this. If you use wp-cli, you can use the wp search-replace command. Otherwise, this is a great tool. Both of these tools will automatically handle doing a proper search and replace inside of any serialized strings.
Also remember to clear out your cache.

Related

Update Wordpress database, change post_content hardcoded URLs

I am not a huge expert in MYSQL nor Regex (I guess I need to use some here), I would appreciate any help.
So my problem is that I would like to change some hardcoded URLs in Wordpress post contents to different ones.
Here is an example of a URL:
http://cdn1.domain.com/wp-content/uploads/2017/05/16211742/Screenshot_051117_101304_AM.jpg
Now, 'cdn1' can be cdn, cdn1 or cdn2. We might need to run 3 queries, but that is not a problem.
I would like to change all instances of this to:
//domain.com/wp-content/uploads/2017/05/16211742/Screenshot_051117_101304_AM.jpg
So basically remove the cdn (cdn, cdn1, cdn2) part, and remove the timestamp URL part before the filename.
The Wordpress database is something like this:
UPDATE wp_posts
SET post_content =
WHERE
Thank you very much!
First of all, take a database Backup for safety.
Then you can do this with SQL Command like this
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
OR you can do this with the plugin called: WP Migrate DB
There has a tutorial on the plugin page. check that.
Hope it will help you. :)

how change url permalink in wordpress database by sql query

I transfer WordPress website from localhost to live but there some url and images url not changes, how can change URL permalink in WordPress database by sql query or any other method.
I use below sql query but anythings not happen please help me...
UPDATE Wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
Thanks in advance
Here is a link to an article from the official wordpress.org page, it covers most of the url changing topic.
It shows the several diverent ways how to do it and also the sql way via phpmyadmin. The raw sql is not shown, but there are several methodes.
In this Blog post a very simple way is described.
I copied the relevant sql statments from the blog post:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
This should change the Url's easy

Wordpress database: How to remove a word from all posts

I've a word called "[stink]" in all my wordpress posts (and they're many). I would like to remove it from all at once. I've got access to mysql/phpmyadmin.. any sql command that could make this?
Thank you in advance.
You can try something like this
UPDATE wp_posts
SET post_title = REPLACE(post_title, '[stink]', ''),
post_content = REPLACE(post_content, '[stink]', '')
WHERE post_title LIKE '%[stink]%'
OR post_content LIKE '%[stink]%'
Note: Make sure that you have a solid backup before you do any changes to your database.
Here is SQLFiddle demo
Since you have access to phpMyAdmin, you can take advantage of the graphical search and replace rather than having to use SQL (which was nicely explained by peterm). From within the table (wp_posts in the case of WordPress), click the Search tab then the Find and Replace text near the top of the screen. Enter the text you wish to search for ([stink]) and what you want to replace it with (sounds like nothing), then select the table from the dropdown (you'll have to do it twice to get both post_title and post_content).
However, some WordPress instances seem to serialize their database entries. In that case, you'll need a different set of tools entirely.
As peterm notes, make sure you have a backup before making changes to your database.

Mysql: bulk delete images from posts while still using their thumbnails

I am new in MySQL.
I would like to delete all the images that were uploaded to posts and pages of a Wordpress site, while still using them as attachments/thumbnails (as featured images).
That is why, I can’t bulk delete them from the media library, only from within posts and pages.
Since it’s a huge amount of images, I’d prefer using mysql command.
The string of the images is always written as follows - <img xxxx>, where xxx is varied based on the img location and other details such as alt, width and height etc.
The table is wp_posts and the fieldname is post_content
The closest command I came across to is –
UPDATE wp_posts SET post_content = REPLACE(post_content, '<img%>', '')
WHERE post_content LIKE '<img%>';
It doesn’t work.
Any clues?
I'm not familiar with WordPress database structures, and can't figure out exactly what you mean, but don't you just mean this:
UPDATE wp_posts SET post_content = '' WHERE post_content LIKE '<img%';
This will delete everything from the post_content column that starts with '< img'. Alternatively you can do NULL instead of ''.

Unserialize, Serialize again and Update values

I'm working on a migrated WordPress, site url changed, everything works fine except some serialized data stored by a plugin.
The data is stored in the wp_options table, in the option_value column, for each record that the plugin saved.
So the data is still there, the problem is that when the url changed, it didnt get re-serialized (the count of the string content still thinks it's the old url lenght), therefore the plugin isn't working properly.
So, to find exactly the records that need to be updated, I use
$t1 = $wpdb->prefix . "vslider";
$t2 = $wpdb->prefix . "options";
$records_ineed = $wpdb->get_results("SELECT * FROM '".$t1."', '".$t2."' WHERE '".$t1."'.option_name='".$t2."'.option_name");
That gives me exactly the records that I need to re-serialize (it matches the name of the record created in the plugin table, with the record created in the wp_option table)
What do I do now?!
How do I take only the option_value of each, unserialize it, reserialize it and update the existing value in the db?
Should I save the reserialized values to a new table, and then replace from that table back to wp_options? How?
Otherwise what are other solutions?
There is no need to do that , what you need is to import the value as - is . it is an array and it will work fine as such as long as you do not alter the data in any way.
At any event , when you import migrate a wp site to another URL , there is absolutely no need to read the wp-options table´s columns one-by-one .
What you need to do it just dump your SQL from the Original ( old-domain ) site , then import into the new-domain , and then run these queries :
/**
To update WordPress options with the new blog location, use the following SQL command:
**/
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
/**
After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as abolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
**/
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');
/**
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
**/
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');
Just for verification , after running those commands , go back to the options table and verify that your home and site_url functions are both correct as for the new-domain data.
If you do still want , for some obscure reason, insert data directly into the options table manually ( ?? why ) then you should consider using get_post_meta() and update_post_meta() function which will take care of the serialization.