sql command removed all my post_content and replaced it with urls - mysql

I ran this sql command as was trying to put a slash after domain.com so image urls worked when moving a wordpress website between domains and now all the post_content fields are just urls?
like this
http://domain.com?page_id=7
Any ideas why this happened or any way to change it back?
UPDATE wp_posts SET post_content = replace(post_content, "domain.comwp-content", "domain.com/wp-content");

Related

Replacing a string that start with and end with in phpmyadmin

I'm trying to update a particular url in wordpress post_content table. I have over 5000 differents urls to update for a single same one.
So in clear I have 5000 urls that all starts with :
domain.com/params.php?....
AND always ends with :
?e=
I want all those url to be replace with a single one without parameters in so they will all send to domain.com/page.html
So is there a way to replace all the urls without having to manually doing it ?
Thanks
Is this what you are looking for?
update post_content
set url = 'domain.com/page.html'
where url like 'domain.com/params?%?e=0'
This phrases as : replace all urls that start with 'domain.com/params?' and end with '?e=0' with 'domain.com/page.html'.
No it is not working. It's being written as it :
Update `wp_posts`
set post_content = 'domaine.com/newpage.php'
where post_content like 'domaine.com/ads.php?city=%e='
so it should take all the queries starting with domaine.com/ads.php?city= until e= but it is not and returning 0 value.
Some knows what is wrong ?

Replace HTTP:// to HTTPS:// in WordPress

With Google getting picky about HTTPS on sites, I was hoping to be able to do a quick and easy SQL Query to search & replace anything http:// with https://
I normally do something like the below for moving hosts:
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
So I tried to do something like
UPDATE `wp_commentmeta` SET 'meta_value' = REPLACE(`meta_value`, 'http://', 'https://');
But it didn't seem to work. Anyway to do the ENTIRE database at once?
I have tried a few options on S.O.F., but nothing worked well.
I prefer not to have to install a plugin as a "fix"
If there is mySQL or htaccess script, I am more interested in those solutions.
If you have access to edit your .htaccess file, you can add the following into it:
RewriteEngine on
# force SSL
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
The code above will redirect with 301 (permanent), if don't want to use a 301 redirect, you can simply change the last section on the last line from [L,R=301] to [L,R].
If you want to be a little more thorough with your SQL replacement, you can usually find all the necessary links inside the posts table inside the guid column (featured images) and the post_content column (backlinks etc). And then ofcourse also inside the post_meta table - meta_value column and home/siteurl inside your options table. Here is the SQL Query that I normally use:
UPDATE wp_options SET option_value = replace(option_value, 'http://example.com', 'https://example.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE (guid, 'http://example.com', 'https://example.com');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://example.com', 'https://example.com');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://example.com','https://example.com');
You can either try WP CLI or the Search Replace DB from Interconnect/it.
If you use the later, you can delete folder after replacing the URL.
You can try this free Wordpress plugin:
https://wordpress.org/plugins/better-search-replace/
Also checkout this article for other ways:
https://kinsta.com/knowledgebase/wordpress-search-and-replace/
Note that you should NOT replace GUIDs according to https://wordpress.org/support/article/changing-the-site-url/#important-guid-note:
the second part of that is that the GUID must never change. Even if you shift domains around, the post is still the same post, even in a new location. Feed readers being shifted to your new feeds when you change URLs should still know that they’ve read some of your posts before, and thus the GUID must remain unchanged.

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 to use wildcards on YouTube ID inside MySQL command?

Today I found that my site (WordPress-based) has some mistakes in YouTube urls, like "https://www.youtube.com/embed/VIDEO_ID&autoplay=1". The autoplay should be preceded by ?, so it's returning error.
How can I use mysql to correct it? I know that I can use something like:
UPDATE wp_posts SET post_content =
replace(post_content, '/embed/VIDEO_ID&autoplay', '/embed/VIDEO_ID?autoplay' ) ;
But how to deal with the VIDEO_ID?

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 ''.