Copying the Body Field to the a CCK Field in Drupal 6 using Views Bulk Operations

The default Drupal Body field can be awkward to work with because it handcuffs the designer by not being wrapped in a div, making it difficult to style. Putting your body text in a CCK field instead gives you the extra div handle needed to style the field. If you already have content in the default body field and want to move it to a CCK field, here is a way to do it for all of your nodes at the same time.

  1. If you'd like to retain the filter (which impacts the formating, such as replacing new lines with paragraph tags) applied to your body content, edit the new CCK field in its content type definition and under 'Text Processing', select 'Filtered text (user selects input format)'.
  2. Install Views Bulk Operations
  3. Navigate to this view added by Views Bulk Operations: admin/content/node2
  4. Set up the filter at the top of the page to filter the list of nodes you want the changes to apply to.
  5. For the Bulk Operation, chose 'Execute arbitrary PHP script'.
  6. In the list of nodes that follows select the desired nodes, or check the box at the top of the list to select them all.
  7. Click 'Execute'.
  8. On the page that follows, under 'Set parameters for Execute arbitrary PHP script', in the 'PHP script' text box enter the following code, replacing 'field_fieldname' with the name of your CCK field (go to the content type 'Manage Fields' dialog to learn the name of your field).

    $object->field_fieldname[0]['value'] = $object->body;
    $object->field_fieldname[0]['format'] = $object->format;
  9. Click 'Next'.

Feel free to leave me questions or comments below.