• I want to replace some content in posts within a certain time period. For example, the posts from Jan 2020 to Feb 2020.
    How do I modify the following query to achieve that?

    update wp_posts set post_content=
    replace(post_content, ‘testing’, ‘example’);

    • This topic was modified 2 years, 11 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not a Requests and Feedback topic
Viewing 1 replies (of 1 total)
  • Dion

    (@diondesigns)

    Use the BETWEEN comparison function. Example:

    UPDATE wp_posts
      SET post_content = REPLACE(post_content, ‘testing’, ‘example’)
      WHERE post_date BETWEEN '2020-01-01 00:00:00' AND '2020-02-01 00:00:00';

    Do not use the post_date_gmt column in the comparison because it is not indexed. Also give some thought to limiting the query to published posts and/or specific post types.

    And make a backup of the wp_posts table before you execute the query!

Viewing 1 replies (of 1 total)
  • The topic ‘Mysql query to search and replace post content for certain posts’ is closed to new replies.