Ask your WordPress questions! Pay money and get answers fast! (more info)

Replace post_content for all posts in MySQL WordPress

  • SOLVED

I have about 200 posts in an existing WP installation. I want to replace the main content of each post with the new boilerplate text. The boilerplate will be the same for all posts, and it will contain paragraph breaks.

Currently, each post has different text for post_content. I want to replace ALL of the existing MySQL post_content fields with the same boilerplate text. I have very little experience running commands in MySQL, but I'm guess this is a relatively straightforward, one-shot replacement.

Thanks!

Answers (2)

2014-09-19

John Cotton answers:

UPDATE wp_posts SET post_content = 'MY BOILER PLATE TEXT' WHERE post_type = 'post'

That will update each row of posts with your new text.

If you've changed the name of your table (ie customized the prefix) you'll need to change the table name wp_posts to whatever you have.


dirtcastle comments:

I have a few clarifying questions.

1. I'm using phpMyAdmin. Should I enter this in the "Run SQL query/queries on database" field under the "SQL" tab?

2. What about paragraph breaks? How do I indicate paragraph breaks?

Thanks!


John Cotton comments:

<blockquote>1. I'm using phpMyAdmin. Should I enter this in the "Run SQL query/queries on database" field under the "SQL" tab</blockquote>

Perfect.

<blockquote>2. What about paragraph breaks? How do I indicate paragraph breaks?</blockquote>
Remember that WP will introduce p tags automatically when run through the_content filter. So carriage returns in your boilerplate are sufficient.


dirtcastle comments:

It works! Thank you!

2014-09-19

timDesain Nanang answers:

Hi Sir,
I can create the script that will update your posts (post_type)

Steps:
1. create a boiler plate (formatted text, image, video, etc) as a page, then get the ID.
2. put the file (that i will create) in the server
3. run the script via browser
4. finish

do you interested?


dirtcastle comments:

Thank you for the answer.

I would prefer to do this via phpMyAdmin, if possible.


timDesain Nanang comments:

I prefer you continue this job with John.
I'll be ready if there is no response from him.

Thank you.


timDesain Nanang comments:

Hi sir,

you can use <strong><p></p></strong> tag or new line <strong>\n\n</strong> to indicate the new paragraph.

1. go to phpmyadmin
2. select the database
3. click SQL tab on the right
4. run this code:

UPDATE `wpd_posts` SET `post_content` = '<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p><p>A new paragraph willbe created/ placed  here. Do you need more?</p><p>This is another paragraph.</p>\n\nHmmm, You can using new_line (twice) to indicate the new paragraph' WHERE `post_type` = 'post' ;


timDesain Nanang comments:

If the boilerplate have a thick sign ('), you need to add a backslash (\) before it
<code>
UPDATE `wpd_posts` SET `post_content` = '<p>I\'ll give an error if you do not put the backslash.</p><p>This is another paragraph.</p>\n\nHmmm, You can using new_line (twice) to indicate the new paragraph' WHERE `post_type` = 'post' ;
<code>

change wpd_posts with the posts table