Support » Plugins » Hacks » Update post_content in database

  • I have over 2000 pages in my wordpress site and I want to replace the post content on them with updated information.
    The issue I’m having is part of the content is the company name which will be dynamic on each post. I also need to do this by category.

    First, I realize I can use phpmyadmin and clear out the contents and the custom field I need to insert into the post content is housed in wp_postmeta.metakey which is ‘Supplier’. I need to insert the wp_postmeta.metavalue for that key into the corresponding post_content in wp_posts.postcontent. Right now, for example, lets say I want to do this for category_id 9. How would I go about clearing out the post content and then putting in new content?
    To clarify, I want to clear out the current content and then have something like this:

    “No current data for ” put supplier name here from post_meta data “. Please contact us for more information.”
    Thanks for any insight!

Viewing 3 replies - 1 through 3 (of 3 total)
  • That will be a complex query with like 4 joins. Without test data and running some tests it’s not a trivial task to compile that query. The slower but easier way would be writing a plugin that just uses WordPress functions.

    In case it takes too long to process and the script may be terminated, you can track which posts been updated by setting a meta_key. Another thing you can do on bulk updates is DISABLE KEYS for the tables you change and re-enable them when finished, this should also speed up the process.

    Thread Starter jshamm

    (@jshamm)

    So an Update wp_posts with a concatenation of “text” wp_postmeta “more text” where category_id = 9 would necessarily work? This stinks. Individually going through 2000 posts is going to take forever.

    Moderator bcworkz

    (@bcworkz)

    You could break up the execution loop into segments and run them separately. You can also set_time_limit(600); in wp-config.php. Just be sure your script is flawless before doing so, or you could have a long wait until you get your server control back.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Update post_content in database’ is closed to new replies.