2

I am in the process of learning WP-CLI and I typed in the command line mistakenly wp post generate instead of wp post generate --help

Now I have generated the default 100 posts, however, this is a good opportunity for me to try to delete these 100 posts using WP-CLI.

However, I could not figure it out. So is it possible to delete a range of posts by ID like for example from 1970 to 2070 or using the time they were generated as they are all generated at the same time all this with WP-CLI.

1 Answer 1

2

Nope, unfortunately not... I was looking for the same thing more or less (range by ID instead dates) and since wp media regenerate supports entering an ID range I thought it should be possible...

# Re-generate all thumbnails that have IDs between 1000 and 2000.
$ seq 1000 2000 | xargs wp media regenerate
Found 4 images to regenerate.
1/4 Regenerated thumbnails for "Vertical Featured Image" (ID 1027).
2/4 Regenerated thumbnails for "Horizontal Featured Image" (ID 1022).
3/4 Regenerated thumbnails for "Unicorn Wallpaper" (ID 1045).
4/4 Regenerated thumbnails for "I Am Worth Loving Wallpaper" (ID 1023).
Success: Regenerated 4 of 4 images.

You could export your posts by date range first via

wp export --dir=/tmp/ --user=admin --post_type=post --start_date=1970-01-01 --end_date=2070-12-31

then open the generated XML-file(s), select all <wp:post_id>XYZ</wp:post_id> in your editor (like SublimeText or VSCode), get rid of the markup and format the IDs as space-separated list and then use the gathered IDs to bulk delete like this

wp post delete 1001 1009 1028 1030 1044 1050

Very cumbersome, I know... Maybe create an issue over at the according Github-repo and request this feature?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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