WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need to do a global search and replace across all posts (8 posts)

  1. tomhanna
    Member
    Posted 8 years ago #

    I have used WordPress for a couple of business sites (real estate) and because I've changed the company I'm licensed with I need to change the company name, phone number and my email address in all posts. Is there any way I can do this without going through post by post? Any possibility for doing a search and replace in the database directly? I have access to phpmyadmin and I could also download a database backup if there's a Windows utility that would let me do this.

  2. I can't think of a way to replace a string with another string directly via a query, so best to write a PHP script that grabs the post from the database, replaces any instances of foo with bar in the post, and then UPDATE's it.

    http://codex.wordpress.org/Function_Reference/wpdb_Class

    Can you handle that or do you need help?

  3. tomhanna
    Member
    Posted 8 years ago #

    I'll take a look at it and see if I can figure it out. Thanks for the reference.

  4. tomhanna
    Member
    Posted 8 years ago #

    Well, of course trying to figure out how to do that I ran across this function that worked just fine in phpMyAdmin:

    UPDATE wp_posts SET post_content=REPLACE(post_content, 'xyz', 'abc');

    Tested it on one blog and it worked just fine.

  5. Oh, awesome. *gives a thumbs up and makes a mental note that there is REPLACE in MySQL*

  6. mcgarva
    Member
    Posted 8 years ago #

    Or if you don't want to write query strings, then export wp_posts from phpMyAdmin, edit it as a text file someplace where you can see exactly what you are doing and can't break your blog, and then re-import.

  7. OperaManiac
    Member
    Posted 8 years ago #

    i am sure i saw a plugin which did just that on the wordpress codex.

  8. flanker
    Member
    Posted 8 years ago #

    Hi, I'm looking to do the exact same thing here, using megarva's solution. A little new to phpMyAdmin, though. How do I do the re-import? Thanks for the help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.