3

I would like to know how to bulk delete posts from a specific category using the WP-CLI, any tip?

10

This should delete all posts in your category:

wp post delete $(wp post list --cat=your_category_ID --format=ids)

Or directly:

wp db query [<your_sql_query>]

For more info:

wp post delete --help
wp post list --help
wp db query --help
| improve this answer | |
0

Actually update wp-cli needs to use the following command to delete all products for a category of Woocommerce installation:

wp post delete $(wp wc product list --category=category_id --user=admin_username) --force

Since Woo only allows to delete 100 products per time you can use the following bash command to create loops using a step value of 100.

for run in {1..2}; do wp post delete $(wp wc product list --category=category_id  --user=admin_username) --force; done

this one deletes 200 products in 2 steps of 100 product each

for run in {1..3}; do wp post delete $(wp wc product list
--category=category_id --user=admin_username) --force; done

this one deletes 300 products in 3 steps of 100 product each

and so on...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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