Is it possible to mass update nodes from, say, "Comments Read/Write" to "Comments Disabled" for all nodes of a certain content type?

I changed the Content Type setting and that worked for all the other nodes types, except for a certain Node type that has given us problems in the past.


4 Answers 4


There's a module called Views Bulk Operations.

I never tried to do it, but I think you can write your own operations for this module pretty easily.

  • Thanks. We do have that and it allows me to filter the options, just not the mass update of turning off "Comments" that I need - that I can see.
    – user6347
    Mar 22, 2012 at 19:38
  • 3
    The VBO description says "Drupal Core or Rules actions can be used." You have to code this action in PHP. Since this would call all necesary update/save hooks on the nodes as well this would be a clean solution.
    – BetaRide
    Mar 23, 2012 at 5:59
  • VBO for D7 allows you to use the "Modify entity values" action to change the comment status without coding. In D6, you can always use the "Execute PHP code" action to change each node. May 8, 2012 at 10:01

Not for the weak of heart, and this bypasses the chance for hooks to fire on the node save / update as well as revisioning, but I usually do this with direct queries.

SET comment = 0
WHERE type = 'some_type'

should do it. Make sure you take a backup to be safe. If you are on Drupal 7, the comment status is also in node_revision, so you need to do

UPDATE node_revision nr 
INNER JOIN node n ON n.vid = nr.vid 
SET nr.comment = 0
WHERE n.type = 'some_time'

as well.


Disable comments here first:

structure->content types->{node_type}->edit->comment settings

To update the nodes use hook_update below:

 * Disable comments on node_type
function hook_update_N(&$sandbox) {
  $content_type = 'node_type';

  // Initialize batch.
  if (!isset($sandbox['total'])) {
    $query = db_select('node');
    $query->condition('type', $content_type);

    $sandbox['total'] = $query->execute()->fetchField();
    $sandbox['progress'] = 0;

    if (empty($sandbox['total'])) {
      $sandbox['#finished'] = 1;
      return t('No %type nodes exist in database.', array('%type' => $content_type));

  // Get and update nodes.
  $nids = db_select('node')
    ->fields('node', array('nid'))
    ->condition('type', $content_type)
    ->range(0, 10)

  if (!empty($nids)) {
    $nodes = node_load_multiple($nids, NULL, TRUE);

    foreach ($nodes as $node) {
      $node->comment = 1; // I set comments as 1 where value of 2 enables the comments.
      node_save($node);   // Re-save the node.

  // Increment & check progress.
  $sandbox['progress'] += count($nids);
  if (empty($nids) || $sandbox['progress'] >= $sandbox['total']) {
    $sandbox['#finished'] = 1;
    return t('Updated @count nodes.', array('@count' => $sandbox['progress']));
  else {
    $sandbox['#finished'] = $sandbox['progress'] / $sandbox['total'];

Do not forget to replace 'node_type' to your node type.

  • What is a node_type? You mean content_type? Also this didn't work for me. I'm trying to unpublish content and the only hook that works are the views hooks.
    – AlxVallejo
    Jun 6, 2014 at 22:40

If you're looking for a Drupal 6 solution that does not involve SQL queries or running your own PHP code via VBO or custom module, there is also Mass Change. It allows you to change statuses, including comment status, for all nodes of a particular content type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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