Bulk replace content inline hyper link as CCK link field

I have a Drupal site that need to replace some content inline hyper links as CCK link field. The reason is: link field is more simple and user-friendly for my client, which don't need the BUeditor to input the link into content. So simply:
  1. Add new link field (e.g. "field_link" within this example) for the existing content type (e.g. "newslink" within this example)
  2. Use Devel and run the following code snippet, which loop though all target content, parse the hyper link, and insert it into link field
  3. Activate the autonodetitle, so replace the node title with field_link's title
  4. Also hide the body of this content type
  5. Update the Views will corresponding changes
Code snippet: nid); if (preg_match("/\s*(.*)\s*", $node->body, $matches)) { $node->field_link[0] = array( 'title' => $matches[2], 'url' => $matches[1], 'attributes' => array( 'target' => 'default', 'class' => '', 'rel' => '', ), ); node_save($node); } } ?>
NOTE: always backup database before critical hack :P

Add new comment