0

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?

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 )

2
  • thanks! you mean UPDATE $wpdb->posts instead of UPDATE wp_posts ?
    – sound wave
    Nov 5 '19 at 13:58
  • @soundwave yes :) Nov 6 '19 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.