Skip to content

Instantly share code, notes, and snippets.

@jplhomer
Created February 25, 2015 16:38
Show Gist options
  • Star 43 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save jplhomer/646927e569548bca4f4e to your computer and use it in GitHub Desktop.
Save jplhomer/646927e569548bca4f4e to your computer and use it in GitHub Desktop.
Disable all comments/pings in WordPress with WP-CLI
$ wp post list --format=ids | xargs wp post update --comment_status=closed
# Output:
# Success: Updated post 2514.
# Success: Updated post 2511.
# Success: Updated post 2504.
# Success: Updated post 2499.
# Success: Updated post 2441.
# etc...
$ wp post list --format=ids | xargs wp post update --ping_status=closed
# Output:
# Success: Updated post 2514.
# Success: Updated post 2511.
# Success: Updated post 2504.
# Success: Updated post 2499.
# Success: Updated post 2441.
# etc...
@cantoute
Copy link

$ wp post list --post_type=page --format=ids | xargs wp post update --ping_status=closed

@ryanlabelle
Copy link

Amazing! Thank you.

@defulmere
Copy link

Nice.

@zahardev
Copy link

zahardev commented Dec 9, 2021

Thanks!

@Ciantic
Copy link

Ciantic commented Jan 11, 2022

Also, if you want to disable them by default, this should turn them off:

wp option update default_pingback_flag ""
wp option update default_ping_status ""
wp option update default_comment_status ""

@pstengel
Copy link

pstengel commented Mar 7, 2022

This method is a bit faster if you have many posts and not all of them need the change:

$ wp post list --comment_status=open --format=ids | xargs wp post update --comment_status=closed
...
$ wp post list --ping_status=open --format=ids | xargs wp post update --ping_status=closed
...

@naqirizvi
Copy link

naqirizvi commented Feb 21, 2023

If you like to toggle them for Posts only then here is the quickest way.

wp post list --post_type=post --comment_status=open --format=ids | xargs wp post update --comment_status=closed
wp post list --post_type=post --ping_status=open --format=ids | xargs wp post update --ping_status=closed

@tyrann0us
Copy link

Disabling pings and comments can be simplified into one command:

wp post update $(wp post list  --format=ids) --ping_status=closed --comment_status=closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment