Is there a WP-CLI command to disable comment windows for all existing posts (pages/blogposts)?

I ask this since when I change a theme for a site I have, all pages in that site getting their comment windows again and I need to individually disable comments per each page.

In this particular site I have up to 10 webpages but in any case I'd like to that with WP-CLI. Is it possible?

If you don't know a way with WP-CLI please at least share another good way you know.

  • 1
    If changing theme is bringing back comment forms that were previously hidden correctly then it's worth checking that your new theme does properly hide comment forms according to your post settings. – Andy Macaulay-Brook Apr 5 at 15:44
up vote 6 down vote accepted

Here is an untested suggestion for wp-cli approach:

We can list post IDs of published posts with open comment status with:

wp post list --post-status=publish --post_type=post comment_status=open --format=ids

and update a post to a closed comment status with:

wp post update 123 --comment_status=closed

where 123 is a post id.

We can then combine those two into:

wp post list --post-status=publish --post_type=post comment_status=open --format=ids \
| xargs -d ' ' -I % wp post update % --comment_status=closed

or

for post_id in $(wp post list --post_status=publish \
    --post_type=post --comment_status=open --format=ids); \ 
do wp post update $post_id --comment_status=closed; done;

Then there's the ping_status as well to consider.

There are other ways than wp-cli but please remember to take backup before testing.

You can execute SQL query to change comment status of all posts using wp db query command.

wp db query "UPDATE wp_posts SET comment_status = 'closed';"

use this command to install the plugin

wp plugin install disable-comments

Use it from backend it has lots of Options

Plugin Url: https://wordpress.org/plugins/disable-comments/

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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