Support » Fixing WordPress » Changing String in All Posts

  • If I have a string in multiple posts–say the string “ABCDEFG”, is there a way that I can do a post-wide search-and replace, to replace it with something else?

    If yes, then can this also be done at the HTML level?

Viewing 8 replies - 1 through 8 (of 8 total)
  • You need to have a plugin to do that. Use regular expression to loop over the posts in a function called by a post_content hook.

    try searching on search and replace. I think this has been discussed before. you sound like you want a one-shot update of content, not a plugin that converts every time the content is loaded.


    Here is a basic plugin:

    Plugin Name: Plugin name goes here
    Plugin URI: The plugin's URI goes here
    Description: Description goes here
    Author: Name goes here
    Version: Version goes here
    Author URI: Your URI goes here

    function replace_text_in_posts($content) {

    return str_replace("text to find", "text to replace it with", $content);

    add_filter('the_content', 'replace_text_in_posts');


    But yes, as davidchait mentioned, if this is simply a one time thing, you could always do something like an SQL query to replace the text.

    Yes, I’m looking for a one-shot change. Is there a simple way to do it? If not, I can probably figure out an SQL statement that’ll cover the changes for me.

    Something like:

    UPDATE wp_posts SET post_content <something> WHERE post_content LIKE (SELECT post_content FROM wp_posts WHERE post_content LIKE <search string>)

    You saw the post immediately above yours?

    Yep. Not bad for dynamic search/replace, but not what I want.

    After a bit of searching, I found this plugin:

    It gives you a new panel, with ‘search and replace’, and will go through and do an SQL replace of text.

    It is a plugin, but not in the sense that it will execute on all posts. It simply gives you a form in your admin panel which lets you do a SQL search and replace. It does not need to run on all posts because it does it directly to the database.

    I will have to add this to my list of useful plugins 🙂

    Thanks, that’s positively brilliant 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Changing String in All Posts’ is closed to new replies.