Resave all nodes of a particular Content Type

Public

Some times you need to trigger a node_save on many nodes to trigger something. Replace 'page' with your desired content type's machine name.

Get raw version
php
  1. <?php
  2. $query = new EntityFieldQuery();
  3. $content_type = 'page';
  4.  
  5. $query->entityCondition('entity_type', 'node')
  6. ->entityCondition('bundle', $content_type )
  7. ->propertyCondition('status', 1);
  8.  
  9. $result = $query->execute();
  10.  
  11. if (!empty($result['node'])) {
  12. $nids = array_keys($result['node']);
  13.  
  14. foreach ($nids as $nid) {
  15. $node = node_load($nid, NULL, TRUE);
  16. node_save($node);
  17. }
  18. }
  19. ?>