Solution 1 :

Why you just dont do one php foreach with all results
from this table and then replace the results of that field with simple regex:

$str = '<div class="inhoud"><h3>abc bac</h3><ul> <li><a href="a">abc bac</a></li> <li><a href="b">abc bac</a></li> <li><a href="c">abc bac</a></li></ul> </div> <div> your next data</div>';

$str = preg_replace('~<div([^>]*)class="(.*?)inhoud(.*?)">(.*?)</div>~im', '', $str);

Solution 2 :

After a couple of hours I finally managed to do it with this SQL update:

UPDATE `wp_posts` SET `post_content` = REGEXP_REPLACE(post_content,'<div class="inhoud">(?s)(.*?)</div>','')

Problem :

I am trying to remove a specific div and it’s content from a large number of WordPress posts.
Instead of just using ‘display:none’ to make the div invisible, I would like it to be removed permanently.
That’s why I prefer to remove the div and it’s content from the SQL database. The div looks like this:

<div class="inhoud"><h3>abc bac</h3><ul>
<li><a href="a">abc bac</a></li>
<li><a href="b">abc bac</a></li>
<li><a href="c">abc bac</a></li></ul>
</div>

In short, I would like all divs with the class inhoud to be removed from the posts content.

I have tried several things, including this regular expression:

UPDATE `wp_posts` SET `post_content` = REGEXP_REPLACE(post_content,'<div class="inhoud">.*?</div>','')

That didn’t do much. What am I doing wrong and what is the correct approach to this?

Comments

Comment posted by Smarketing

That didn’t work for me. I added the code to the functions.php which might have been the wrong place. I couldn’t figure out how to do it with php. Thanks for helping though.

By