skip to Main Content

I have table name wp_posts and in post_content column there is a description of my posts (in HTML).

I would like to have a query that searches in post_content column and selects the tag starting with <div class or no class> and remove whole tag.

I dont want to remove anything inside the tag, just remove the tag

This :

<div> or <div clas="sada">
some text
</div>

Would become this:

some text

My MYSQL version is 15.1.

3

Answers


  1. Chosen as BEST ANSWER

    I find a solution here, write it here for others:

    update wp_posts
    set post_content = REGEXP_REPLACE(post_content, '</?div.*?>', '');
    

  2. if you are using wordpress, you must have php access, so you can use strip_tags() to remove the html from the variable.

    Login or Signup to reply.
  3. In your case you can write a short script which fetch all wp_posts elements. Then
    you iterate this collection and remove with reg. expression function the div
    tags and update the field again in your database.

    This would be the expression which remove the div tag.
    $wp_content = preg_replace('/<[/]{0,1}div[^>]*>/i', '', $wp_content);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search