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 Answer 1

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 ? Commented Nov 5, 2019 at 13:58
  • @soundwave yes :) Commented Nov 6, 2019 at 12:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.