Ben Racicot
Ben Racicot

Reputation: 5903

Bulk remove a word from all WordPress URLs

I've imported about 600 pages into my WordPress database and most (not all) of them have the word "park" at the end of their new URL's

domain.com/awesome-park/

I would like to bulk remove the word (and its previous dash - )change them via SQL query or other recommended method. Any advice for a safe way to change URLs inside a database would be greatly appreciated.

Upvotes: 0

Views: 330

Answers (3)

David Faber
David Faber

Reputation: 12485

The slug is stored in wp_posts.post_name. So the following should work (this from the first answer above):

UPDATE wp_posts
   SET post_name = REPLACE(post_name, '-park', '')
 WHERE post_name REGEXP '-park$';

I do recommend backing up your WordPress database before running this query!

Upvotes: 0

Adeel Raza
Adeel Raza

Reputation: 634

This simple plugin can do the job.

https://wordpress.org/plugins/search-and-replace/

Note : Remember you should only do this for wp_posts table and take a backup of your database before executing the query.

Upvotes: 1

Taras Velykyy
Taras Velykyy

Reputation: 1801

If you know the table and column where this url has been defined you could run next query:

UPDATE 'table_name' SET 'url_column' = REPLACE('url_column', '-page', '');

Upvotes: 1

Related Questions