Community Documentation

Disable or enable comments for node types en mass

Last updated February 12, 2013. Created by glass.dimly on September 11, 2009.
Edited by chrisjlee. Log in to edit this page.

This snippit allows you to bulk enable or disable comments for nodes through the database.

SQL to disable comments for all nodes of type "story":
UPDATE node SET comment = 0 WHERE type LIKE "story";

comment = 2 would mass enable read/write
comment = 1 would mass enable just read
You can change "story" to "page" or whatever you'd like.

Comments

thanks

that is exactly what I need

Bevin

Well, yes. But...

Well, yes. But...
-- Would love to provide a UI to choose a large number of nodes, but not all of a type.
-- I prefer not to do this kind of thing in production.

D7

You wanna do this via the

You wanna do this via the abstraction layer, do ya?

Yeah, I know you do.

That's why I'm here to help you out, friend!!

<?php
$subquery
= db_select('node');
$subquery->addField('node', 'nid');
$subquery->condition('node.type', 'YOUR_NODE_TYPE', '=');

$num_updated = db_update('node_revision')
->
fields(array('comment' => '2',))
->
condition ('node_revision.nid', $subquery, 'IN')
->
execute();
?>

I couldn't figure out how to do a join in a db_update.

Is it possible?

You need to change the

You need to change the setting in the node revisions table as well. Maybe something like the following in addition to the original query:

UPDATE node_revision, node SET node_revision.comment = 2 WHERE
  node_revision.nid = node.nid AND
  node.type = "story";

Thank you ! A lot easier than using boring unclear VBO !

Page status

About this page

Drupal version
Drupal 5.x, Drupal 6.x
Audience
Programmers, Site administrators

Reference

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here