Disable comment windows for all existing posts (pages/blogposts)

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.

3 Answers
3

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.

Leave a Comment