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

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