Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Last active December 27, 2015 00:29
Show Gist options
  • Save cesarmiquel/7238113 to your computer and use it in GitHub Desktop.
Save cesarmiquel/7238113 to your computer and use it in GitHub Desktop.
Unpublish drupal content
<?php
// Select all nodes of type article created by anonymous and admin
$result = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'article')
->condition('uid', array(0,1), 'IN')
->execute();
// go through results and unpublish each article.
foreach($result as $row) {
$node = node_load($row->nid);
print 'Unpublishing: ' . $node->nid . ' - ' . $node->title . "\n";
$node->status = 0;
node_save($node);
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment