I have a site with a tremendous number of nodes of various content types. I want to set them all to unpublished, and I don't see a way to do that easily without going through page after page after page of content pieces.

I was thinking of doing a query directly on the database: UPDATE node SET published = 0; -- but will this correctly unpublish all content?

Edit: We're dealing with several thousand nodes, and as I understand, there's a hard-coded limit of 50 nodes displayed on the bulk edit page. So I am trying to avoid flipping through dozens of pages.


If you want unpublish all nodes, quick and dirty method is simple sql query UPDATE node SET status = 0; Then clear cache and its done. But if you use Views, they could still show unpublish content depends on settings.

  • So that's really all I need to do? No surprises, other shoes, or unexpected side-effects?
    – user1359
    Oct 11 '11 at 19:47
  • 6
    you also have to update node_revisions if I remember correctly.
    – uwe
    Oct 11 '11 at 21:05
  • I'm updating status field with 0 in both tables: node and node_revision and it was working fine except I observed following scenario: I'm not logged in as admin (not logged in at all) and opening node. For one unpublished node it says no content found and for other unpublished node it shows partial content with pink background. Any idea what could go wrong? Sep 4 '15 at 14:25

If you do not want to do this through SQL, the Content Management Filter module allows you to filter your content greatly, and determine how many rows are displayed on a page (therefore, allowing you to do bulk operations with ease).

Another module worth checking is Views Bulk Operations (aka VBO). It'll make it easy to create a view entirely geared towards bulk updates.

  • I would like to do it through SQL, since that seems the simplest way, but is that query all I need to do? Would there be any unexpected side-effects?
    – user1359
    Oct 11 '11 at 19:46
  • 1
    I would recommend using VBO. There is a drush command called drush vbo-execute see drush vbo-execute --help for more info. Jun 20 '12 at 9:18

I am going to throw out one more option.

Write a test script that

  1. Bootstraps.
  2. Queries the database to find the nids you want to unpublish, then loops over the nids
  3. $node = node_load($nid);
  4. $node->status = 0;
  5. node_save($node);

Depending on your version of Drupal, you may be able to optimize this with node_load_multiple(). Just be sure you have enough memory available and you adjust execution time, if necessary.

Doing it this way should take care of any housekeeping that the node_save() fires.

  • do we need node_save to just update the status alone? cause it will do lot of operations. Oct 11 '12 at 6:03
  • 1
    @Mathankumar, using node_save() will cause all of the related hooks to run. Not using it will mean they don't which may cause weirdness in your system. For example, if you are using moderation your unpublished nodes may not get back to the proper workflow state.
    – mpdonadio
    Oct 11 '12 at 10:54

On the Find Content page at admin/content there's an option for you to do bulk updates including unpublishing of selected nodes. See http://www.gingerfeet.net/drupal-userguide-siteadmin-node

If this doesn't suit your needs, you might want to also look into Views Bulk Operations module.

  • Those options are a lot more work than the single query. Since this is a one-off deal, is there any reason not to do it?
    – user1359
    Oct 11 '11 at 17:53
  • 2
    A reason not to use the UPDATE is when you have triggers that are defined to fire when a node transitions from published to unpublished.
    – mpdonadio
    Oct 11 '11 at 23:06

In Drupal 8 (same in Drupal 7), one of the best ways to mass-unpublish nodes is to do something like the following:

$nodes = node_load_multiple($nids, TRUE);
foreach ($nodes as $nid => $node) {
  $node = $node->setPublished(FALSE);

(Assuming you have an array of $nids to begin with.)

Note that we set TRUE for the node_load_multiple $reset, to conserve memory if there are hundreds or thousands of nodes being operated on.

If you need to do it in a place where there's a normal page load/UI, it would be best to use Batch API to batch the operation... but use the same code as above inside the batch.


Install the Admin_Views module (which is a requirement on all my sites anyway) and then you can use the /admin/content menu to select all Published nodes and bulk-change them to Unpublished. It uses VBO so the interface should be pretty natural (Just look for the "Select all #### nodes" button above the content when you click the SELECT ALL checkbox to do more than 50 at a time). It will use the normal Drupal hooks so it will take longer than an "UPDATE nodes SET status=0" but won't have any bizarre side effects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.