Mass editing a string in a WordPress MySQL Database

Mass editing a string in a WordPress MySQL Database

I’ve encountered many times with the need to change a certain string from a database in order to adapt all images and hardcoded links from one url to a different one. But there are more cases you would want to search & change a string by accessing directly your databases:

  1. images not working and you need to change their URL,
  2. changed the home URL in “settings” and can’t access your blog anymore,
  3. changing a phrase or spelling you’ve been using incorrectly all throughout,
  4. changing all instances of the name and slug of an old custom post type to a new one,

Log into your PhpMyadmin panel and search for the SQL console and use this line:

UPDATE wp_posts SET `post_content` = REPLACE (  `post_content`,  'Item to replace here',  'Replacement text here');

Where wp_posts responds to the name of your posts table which will vary depending on your table index.


Or log in via a shell command:

mysql -u username -ppassword
use mywordpress_table;
UPDATE wp_posts SET post_content = REPLACE (  post_content,  'text to find here',  'text to replace here');
Spartan Race Barcelona

Next Article

Spartan Race Barcelona

No Comments