I have a website on Drupal 6 which is being re-branded. The theme is not a problem. However, the website has hundreds of nodes, most of which have references to the original company name.

Is there a way which I can replace every instance of a piece of text with another in a content type. I'm assuming there's not a proper Drupal way of doing this but I wondered if anyone had achieved this somehow. Possibly by querying the database directly to find and replace the text.

Is it just the node table I'd need to query or is there somewhere else which may be hiding bits of text input by the user? Things like taxonomy aren't used on the site, just basic nodes and views as far as I'm aware.

Presumably it'd be something along the lines of:

UPDATE `node` SET `column` = replace(`column`, 'Old Company', 'New Company')
  • You'll need to consider the revisions table as well, even if not using revisions. I cannot recall the query I ran when I last did this some time ago, but a word of warning everything looked fine, until the client noticed huge chunks of content had been removed! – drmonkeyninja Jan 13 '12 at 11:33

Always search the contrib modules before rolling your own solution; a quick search for 'Drupal find and replace' turned up the Scanner module:

The module has a stable release and looks to do what you need. As always make backups of your database before utilizing modules that alter your data.

  • This worked perfectly. Unfortunately not compatible with the nodewords module so I had to manually work through meta information but Scanner was most helpful. Cheers – Ben Swinburne Mar 6 '12 at 11:25

Depending on the configuration of the site you'll be looking to replace text in the following places, using an sql query like you have:

  • 'body' column from the 'node_revisions' table for the body of the nodes
  • 'field_fieldname_value' column from the 'content_type_name' table for single value CCK fields which are not shared by content types
  • 'field_name_value' column from the 'content_field_name' table for multi valued CCK fields or single value fields shared by content types

Bottom line is: if you're not using CCK, look in 'node_revisions'. If you're using CCK look in 'node_revisions' and the 'content_type_*' and 'content_field_*' tables.

Also, after you do the replace, clear the cache to see the changes. Either from admin or truncate the 'cache_*' tables.

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.