Brandy
Brandy

Reputation: 564

MYSQL remove word from a column in a table

I'm using wordpress and want to go through the entire wp_posts database using MYSQL to remove the word "on" from the slugs.

I've tried these two lines;

update wp_posts set post_name = replace(post_name, '%on-%', '') where post_type = "post";

select *, replace(post_name, '%on-%', '') from wp_posts where post_type = "post";

They dont remove the word 'on' from things such as "12th-annual-helmets-on-kids-campaign"

Thanks guys

Upvotes: 1

Views: 53

Answers (1)

Axel Amthor
Axel Amthor

Reputation: 11106

try

update wp_posts set post_content = replace(post_name, 'on-', '') where post_type = "post";

and omit the %.

Upvotes: 3

Related Questions