2

I need to delete some content from all posts.

Every post starts with this line:

<p style="text-align: center;"><img src="http://i.imgur.com/picture.jpg" alt="" /></p>

So I want to delete this line from all posts from my database at once.

I know I can edit it in phpmyadmin but I do not know how to do it.

Here is how every post looks:

<p style="text-align: center;"><img src="http://i.imgur.com/picture.jpg" alt="" /></p>
<p style="text-align: center;">here is some text.</p>

So basically I want to mass remove this very line:

<p style="text-align: center;"><img src="http://i.imgur.com/picture.jpg" alt="" /></p>

from every post on the site.

Postscriptum, I am completely newbie.

5
  • More of a MySQL question. If you want to do this from PHPMyAdmin then you could try something like this: UPDATE wp_posts SET post_content = REPLACE( post_content, 'from', 'to' ) WHERE post_type = 'post' AND ID = 123;. Where you adjust the from and to values, the ID and post type and the wp_posts table name. You can then remove the ID and post_type restrictions after testing. But remember to BACKUP up your db before!
    – birgire
    Commented May 14, 2015 at 19:26
  • Ok but can you describe how I should do it step by step?
    – davidnsfw
    Commented May 14, 2015 at 19:34
  • 1
    Go to PHPmyadmin -> Click on the required database -> Export your DB -> Run the query given by birgire. If the test works, go ahead altering the query for your requirement.
    – m4n0
    Commented May 14, 2015 at 20:18
  • I have exported the database, now I am on localhost »Database: sitename »Table: wp_posts and there are many files so I do not know which choose?
    – davidnsfw
    Commented May 14, 2015 at 20:30
  • So should I add this in Run SQL query/queries on database sitename? What exactly should I put there? I am bit confused by this post, like I said I am completely newbie.
    – davidnsfw
    Commented May 14, 2015 at 20:41

2 Answers 2

2

To use phpMyAdmin follow the steps below:

Login to phpMyAdmin panel and select your WordPress database.
Click on the SQL tab which will bring you to a page with a SQL query box.

Once you see the SQL query box, like the image shown below, you can run your SQL query there.

UPDATE wp_posts SET post_content = REPLACE (post_content, '<p style="text-align: center;"><img src="http://i.imgur.com/picture.jpg" alt="" /></p>', '');

phpmyadmin SQL Query box

0

Good advice. It worked for me, but I had to put quotes around the table and field name.

UPDATE `wp_edeals_posts` SET `post_content`= REPLACE(post_content, '<p style="text-align: center;"><img src="http://i.imgur.com/picture.jpg" alt="" /></p>', '')

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.