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 = 

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.


Recommended Answers

All 2 Replies

Thank you.

After reading the Wordpress article you referred to

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

the above worked!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.