removing the same code inside every post

  • I would like to remove the following code in all my posts:
    <!– wp:latest-posts {“categories”:[{“id”:…,”value”:”….”}],”postsToShow”:100,”postLayout”:”grid”,”columns”:6,”order”:”asc”} /–>
    What should I do without editing every single post?

  • Hello,

    Since the code you want to remove is identical across all posts, the cleanest way to do this without editing each one is a bulk find-and-replace directly on your database. I’d recommend the Better Search Replace plugin (free on WordPress.org):

    1. Install and activate Better Search Replace.
    2. Go to Tools → Better Search Replace.
    3. In the “Search for” field, paste the exact block string you want to remove:
      <!-- wp:latest-posts {"categories":[...],"postsToShow":100,"postLayout":"grid","columns":6,"order":"asc"} /-->
    4. Leave “Replace with” empty.
    5. Select the wp_posts table.
    6. Run a dry run first (check “Run as dry run?”) to confirm how many matches it finds, then run it for real once you’re happy.

    A couple of things worth flagging:

    • The block code stored in your database uses straight quotes (") and standard dashes, not the curly quotes/dashes shown in your message — so make sure you copy the exact string from the post editor’s Code view, or the replace won’t match.
    • If the block parameters (category IDs, etc.) differ from post to post, a single search string won’t catch them all. In that case you may need a few passes or a more flexible approach.
    • This sits a little outside GeneratePress support since it’s a core WordPress block, but the method above should sort it out.

    • Back up your database first. Search-and-replace on wp_posts is irreversible.

    This sits a little outside GeneratePress support since it’s a core WordPress block, but the method above should sort it out.

  • Thank you for your kind response.
    I was using SSH with some commands and all the same codes in thousands of posts were removed immediately.
    So grateful.

  • Glad to know you are sorted!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.