How to replace a string in all posts in WordPress database?

We had some anomalies in our WordPress sites that some of them old posts have the wrong interpretation of single quotes and double quotes so we had to manually replace all the wrong strings to the correct quotes.

In cpanel, you can open up phpmyadmin to run the following MySQL queries, but first, you need to back up the database.

update wp_posts set post_content =
replace(post_content, '’', "'"), post_title =
replace(post_title, '’', "'");

update wp_posts set post_content =
replace(post_content, '“', '"'), post_title =
replace(post_title, '“', '"');

update wp_posts set post_content =
replace(post_content, '”', '"'), post_title =
replace(post_title, '”', '"');

update wp_posts set post_content =
replace(post_content, '‘', "'"), post_title =
replace(post_title, '‘', "'");

update wp_posts set post_content =
replace(post_content, 'Â', ""), post_title =
replace(post_title, 'Â', "");

update wp_posts set post_content =
replace(post_content, '–', "--"), post_title =
replace(post_title, '–', "--");

That’s it. All abnormal strings in post_content and post_title have been globally replaced in the WordPress database.

Scroll to Top