Apply on existed nodes

Last updated on
30 April 2025

If create computed field on existed nodes, you must update all materials for compute values for new fields.
It is possible with this snippet:

<?php
  $query = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->condition('n.type', 'product');
  $result = $query->execute();
  foreach ($result as $row) {
    if ($node = node_load($row->nid)) {
      node_save($node);
    }
  }
?>

If nodes a lot then need wrap this in batch.

Help improve this page

Page status: Not set

You can: