I wish to replace one string in all my WP posts (over one hundred).

There is a "bulk edit" feature, but I do not think it covers this feature.

I can think of downloading the database, open it with an editor and make a replace. In a GUI editor this may fail since the file is so large. If I read up on database structure and MySQL I can probably isolate the variable containing the post texts and only edit that one. It is probably best to use a line editor like SED.

At present I don't use MySQL and SED daily and it will take some time to experiment with and also verify that file is OK.

Is there any quick way to make an edit-replace command over all my WP posts?

(The reason I need to do this is that the latest update of "Insert PHP" plug-in does not allow PHP written straight into the pages, which I have used.)

  • Globally replacing a simple string in multiple posts is quite simple, I am just not certain this is exactly what you need. Can you give an example of the string, and confirm it is simply added in the editing screen of a bunch of posts Jun 16, 2018 at 14:17

2 Answers 2


There are many ways to do this here a couple:

1) You can use something like:

Better search and replace plugin here: https://wordpress.org/plugins/better-search-replace/


SAFE SEARCH AND REPLACE ON DATABASE WITH SERIALIZED DATA script here: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

Both of these with serialize the data, which is important for many themes and plugins.

There is a good explanation of WP Serialized data here: https://wpengine.com/support/wordpress-serialized-data/

  • Thank you. This will run in web browser which is good for me (I do not have SSH on this server). I am not familiar with the term "serialization", is it something that may affect the result of the action? (I tried to Google it but for safety I ask.)
    – cvr
    Jun 16, 2018 at 15:27
  • Since I am not sure of the consequences of serialization, I should probably use The Search and Replace plugin which "offers an option which handles serialized data" so I can opt out of serialized data?
    – cvr
    Jun 16, 2018 at 16:06
  • Can you please verify the statement in your answer "Both of these with serialize the data". Is this correct or are the editors only capable of handling serialized data? They will not introduce serialized data? Sorry I am very new to serialization, can someone please verify this?
    – cvr
    Jun 16, 2018 at 18:31
  • Yes these both do the same thing. Neither will inject serialization, they just both handle it so if a value is serialized it will keep the sterilization and not invalidate the row.
    – Shane
    Jun 16, 2018 at 18:36

You mention Sed so you may be familiar or comfortable with command line usage. If so, I'd recommend WP-CLI. We use this constantly via SSH to do just that.

After WP-CLI is installed, you will want to run the wp-cli search-replace command. Example usage:

wp-cli search-replace 'old string' 'new-string' --dry-run

Keep --dry-run in place to make sure it's doing what you want it to do. Nothing will be affected in the database. When you're ready to make a permanent change to the database, remove it.

  • Thanks, sounds like a really good idea. I wait a little and see if more suggestions come in before I approve the answer. I dont have SSH on this server (GoDaddy web hosting), can it run over normal WP http interface?
    – cvr
    Jun 16, 2018 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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