0

Hi

I have a site built on Wordpress which has a over 4,000 posts all with the suffix -2 at the end of the post name (due to me forgetting to clear the trash) before running an import).

I would like to remove the -2 from the post names with a little bit of SQL so that for example my-example-post-2 becomes my-example-post and so on.

The table is wp-posts and the field is post_name.

I tried

update wp_posts set post_name = 
replace(post_name,'-2','');

but this didn't work, I suspect but not sure, it may be because it looking for an actual post name of '-2' rather than the equivalent of %-2

Any help really appreciated as although I have backed up my database and will do before running any SQL I don't want to realy mess it up be experimenting on my own further.

Thanks
Mark

2
Contributors
2
Replies
12
Views
4 Years
Discussion Span
Last Post by magicmarkuk
0

Thank you.

After reading the Wordpress article you referred to

UPDATE wp_posts SET post_name = REPLACE ( post_name, '-2', '' );

the above worked!

Thanks
Mark

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.