Home > front end >  Remove all <div tags with SQL Query
Remove all <div tags with SQL Query

Time:02-15

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 5.7.28.

CodePudding user response:

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

CodePudding user response:

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);

  • Related