You have a lot of blog posts on your wordpress self hosted blog where you refer to a particular URL. Now somehow that URL got changed and you need to edit your posts. To change all those URL’s, one way is to go one by one, open and edit all your posts. Not a smart way.
Other way would be to use MySQL and batch edit them at a click of a button. No need to be a techie, anyone can do this.
This was useful for me when recently I made a move from blogger to wordpress. There were about 25 posts where I needed to change a particular URL. Here is how I did and you can do this in under 5 minutes.
- Log on to PHPMyadmin. [Your webhost should have provided the URL to access it.]
- Select your database name from the drop down given on the left hand side.
- In SQL tab type
UPDATE wp_posts SET post_content = replace(post_content, 'OLD CONTENT’, 'NEW CONTENT');
and hit GO.
The above SQL statement replaces all the occurrences of OLD_CONTENT with NEW_CONTENT inside the content(post_content) of all posts(wp_posts). Make sure that wp_posts is indeed the name of your posts table. On shared hosting the name of this table is different sometimes.
For techies: Here is the syntax of MySql Replace function REPLACE(
str
,from_str
,to_str
)
Am searching for a plugin that would do exactly this, i can’t start editing and going over to mysql now, and truth be told, am really not well informed in that area.
Worked like a charm for me – thanks!
But beware! When you copy the command line from the post, the apostrophe characters surrounding the ‘CONTENT’ terms are changed to something else. So make sure you change them back to normal apostrophes before you hit GO.
Oh I guess the code didnt show up. I meant to say that it looks somewhat like this (i hope this works)
[a href=”https://market.android.com/details?id=XXXX”][img src=”http://tablified.com/wp-content/uploads/2011/07/androidicon.png” alt=”” title=”Click to Download from Android Market” width=”300″ height=”48″ class=”alignnone size-full wp-image-4507″ /][/a]
replace the “[ or ]” with “”.
I could use some help. This doesn’t seem to work for me. I get a 1064 error. Here’s what I am trying to do. In each post I have a link that looks somewhat like this:
The difference between each post is the XXXX. So what I wanted to do was replace the whole thing and make it look like this:
[app]XXXX[/app]
So what I did in the SQL was type:
UPDATE wp_posts SET post_content = replace(post_content, ‘’, ‘[/app]‘);
But unfortunately it didnt work. This is the error I got:
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘href="https://market.android.com/details?id=’, ‘[app]‘)’ at line 1
Not really sure what that means. Can anyone help me out?
Let it be noted that if you try this:
UPDATE wp_posts SET post_content = replace(post_content, '"' , '');
You will get an SQL error. In my case getting rid of the helped. Hope this helps someone out there.
Didnt aprove my comment about mysql adm!
Go fuck ur self and ur blog!
@Notebook HP aka Hey – Seems you had a bad day. We approve comments in a batch, sometimes it may take 7-10 days before you will see your comment published.
What about editing “bulk” post titles via phpAdmin?
Thing it’s blog was written in PT-br , now to make all post_name (URL) us english I need to change every post name via wp-admin. But there are 2.500 posts! So I got how to export just post_name table and translated them via Systran. But how do I upload it? First I need to “clean” any data from post_name table them how to import it? via txt? File must be equal structure from which one I export it?
Thanks
Hey Ankur, I am facing the same issue as stated by Mahesh. I has tried to use the trick you suggested but can’t get it working. Can you guide me through this?
Good trick. But, what if I want some some text to be removed from all the posts?
Like, I have some posts, at the end of the each post, there is a word DOWNLOAD. I want that word to be removed from all the posts. How can I do this?
You should be able to do that by checking for the word “DOWNLOAD” at the end of post. I would suggest you to always have a backup in place. Do a SELECT first, once you are satisfied then only do an UPDATE