admin管理员组

文章数量:1193817

I have hundreds of posts whose titles are of the form XmY, where X and Y are natural numbers, for example 18m324.

I'd like to replace m with p in all post titles and slugs, while keeping X and Y unchanged. How to do it in phpmyadmin?

UPDATE wp_posts
SET post_title = 
REPLACE(post_title, 'm' , 'p')
WHERE post_type = 'post' AND post_status = 'publish';

This code should replace in the titles, but what about the slugs?

I have hundreds of posts whose titles are of the form XmY, where X and Y are natural numbers, for example 18m324.

I'd like to replace m with p in all post titles and slugs, while keeping X and Y unchanged. How to do it in phpmyadmin?

UPDATE wp_posts
SET post_title = 
REPLACE(post_title, 'm' , 'p')
WHERE post_type = 'post' AND post_status = 'publish';

This code should replace in the titles, but what about the slugs?

Share Improve this question edited Nov 5, 2019 at 6:09 sound wave asked Nov 5, 2019 at 5:44 sound wavesound wave 2151 gold badge3 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Slugs are saved in the very same table but in the post_name column. So your query would look like this:

UPDATE wp_posts
SET post_name = 
REPLACE(post_name, 'm' , 'p')
WHERE post_type = 'post' AND post_status = 'publish';

By the way, I'd suggest you to use $wpdb->posts instead of just wp_posts ( then it would be compatible with different prefixes, but it's not important if it's just a "local" script )

本文标签: mysqlReplace a character in all post titles and slugs