user676032
user676032

Reputation: 39

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.

Upvotes: 1

Views: 922

Answers (2)

Isaac Bennetch
Isaac Bennetch

Reputation: 12432

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.

Upvotes: 0

peterm
peterm

Reputation: 92795

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

Upvotes: 6

Related Questions