Edit post_content on posts with Featured Image

Great forum! I’m a total newbie to SQL but a quick learner. I have a large database of content, >140k posts. Some posts have Featured Images, others do not.

I would like to edit post_content on posts with Featured Image. I do not need to know anything about the Featured Image, only that the post I edit has one and is not null.

I would basically like to do a simple search and replace in post_content on posts with a Featured Image. I do not want to edit posts that do not have a Featured Image set.

Thank you for any help you can provide.

1 Answer
1

I would do this as follows:

  1. Back up the entire DB (or certainly the wp_posts table!)
  2. Run this query to get all posts that have a featured image:
    SELECT wp_posts.* FROM wp_postmeta INNER JOIN wp_posts ON (wp_postmeta.post_id = wp_posts.ID) AND meta_key=’_thumbnail_id’;
  3. Export the results to a plain SQL file with SQL inserts
  4. Do your search and replace within that SQL file
  5. Reimport the data.

This assumes your tables have the default prefix obviously.

Leave a Comment