Hook for bulk node modifications
Where you place the code depends on when you want it to run. Usually these things goes best in hook_cron(), but cron needs to be set up to run for that to work.

Instead of doing bulk update you might want to consider changing the published value in hook_node_presave() instead, i.e. when saving the node. Example (untested):

function mymodule_node_presave() {
  $w = entity_metadata_wrapper('node', $node-&gt;original);
  $var = $w-&gt;field_status-&gt;value();
  if ($var == 'Closed') {
    $w-&gt;status = 0;
    $w-&gt;save();
  }
}


Concerning your code otherwise it should work afaik, but it would be better to load all nodes at ones. Something like this:

$nodes = node_load_multiple(array_keys($result['node']));
foreach ($nodes as $node) {
  $w = entity_metadata_wrapper('node', $node);
  $w-&gt;status = 0;
  $w-&gt;save();
}


Cheers,