I have a wordpress blog with 93 posts on it, in which I want to replace [bash] with <pre> but how do I do it please? I need to go through all the posts changing [bash] to <pre> in each one, but the [bash] doesn't appear in every posting but it is in quite a few, too many to do it by hand with one post after another, I'd rather do it in batches if possible.

I believe the posts are stored in a MySQL database, but I can't remember why I believe so!

  • Are the blog posts stored in files or in a database? If a db, which database? – Gilles Sep 6 '13 at 0:07
  • I believe its a mysql database, but I cant remember why I believe so! – boudiccas Sep 6 '13 at 0:35

Assuming that you're running WP on top of a MySQL database, and that your table prefix is wp_, then you'll want to run a query like:

UPDATE wp_posts
SET post_content = REPLACE(REPLACE(post_content, '[bash]', '<pre>'), '[/bash]', '</pre>')
WHERE post_content LIKE '%[bash]%'

Take a backup first, just in case!

mysqldump -h hostname -u username -p your_wp_database_name > backup.sql
  • Sammitch - This is on a hosted space site run by 1and1, with the database name beginning db***** . Does this still apply to your previous answer please? – boudiccas Sep 6 '13 at 0:57
  • The best solution I found was to use a wordpress plugin called 'Search & Replace' which amended the database, and worked very well making my changes. – boudiccas Sep 7 '13 at 8:57

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.