1

I need to run a query for all posts in a WordPress (+30.000)

To remove all content from * only:

I'm reading about possibilites like:

UPDATE wp_posts
  SET post_content = 
  REPLACE( post_content, '</iframe>&', '</iframe>' );


SELECT SUBSTRING_INDEX('', '</iframe>', 1) as result;

But not working.

Thank you so much for the help.

1 Answer 1

1

There does not seem to be a wildcard character for this, so I adapted the solution that is found here: MySQL for replace with wildcard

It only works if there is only 1 in the content of each post. Because it will take the content until and including that .

UPDATE wp_posts
SET post_content = SUBSTR(post_content, 1, LOCATE('</iframe>', post_content)+8)

Notice that the +8 is the length of this string minus 1: </iframe>. You may want to test it on 1 row first.

I just realized this should only be applied to rows that DO have </iframe> in it, or else the rows without it will become empty. So you need it like:

UPDATE wp_posts
SET post_content = SUBSTR(post_content, 1, LOCATE('</iframe>', post_content)+8) WHERE id IN (SELECT id FROM wp_posts WHERE post_content LIKE '%</iframe>%');
Sign up to request clarification or add additional context in comments.

3 Comments

I'm sorry, I think I didn't express myself well (I'm also very new to mysql). I have to remove all the content of all posts of a WP from the string </iframe> What I wanted to put in my first message is to replace </iframe>* (all that goes after </iframe>) for only </iframe>
It worked perfectly. UPDATE wp_posts SET post_content = SUBSTR(post_content, 1, LOCATE('</iframe>', post_content)+8) Thank you very much!
Did you double check that posts/pages without iframes in them did not become empty? If not, no problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.