Skip to main content

wp post delete

Overview

Remove posts from WordPress — either by moving to Trash (default) or with permanent deletion using --force. Supports bulk deletion of multiple post IDs.

What It Does

wp post delete calls wp_delete_post() or wp_trash_post() depending on flags. Without --force, posts are moved to the Trash and can be recovered.

Syntax

wp post delete <id>... [OPTIONS]

Arguments & Options

FlagDescription
--forcePermanently delete (bypass Trash)
--defer-term-countingSpeed up bulk deletes by updating term counts at the end

Basic Usage

Move post to Trash

wp post delete 42

Permanently delete a post

wp post delete 42 --force

Bulk delete multiple posts

wp post delete 12 15 22 --force

Real-World Scenarios

Scenario 1: Purge all trashed posts permanently

for id in $(wp post list --post_status=trash --field=ID); do
wp post delete "$id" --force
done
echo "All trashed posts removed."

Scenario 2: Delete all auto-draft posts

wp post delete $(wp post list --post_status=auto-draft --field=ID) --force

Scenario 3: Delete WooCommerce old order notes

wp post delete \
$(wp post list --post_type=shop_order_note --field=ID) \
--force \
--defer-term-counting

Scenario 4: Safely delete and verify

POST_IDS=$(wp post list --post_type=page --post_status=draft --field=ID)
echo "Will delete: $POST_IDS"
read -p "Continue? (y/N) " confirm
if [[ "$confirm" == "y" ]]; then
wp post delete $POST_IDS --force
fi

Best Practices

  1. List before deleting — always run wp post list with the same filters first.
  2. Use --defer-term-counting on bulk deletes (100+ posts) for much better performance.
  3. Skip --force on production unless you're certain — Trash allows recovery.

Quick Reference

wp post delete <id>                   # Move to Trash
wp post delete <id> --force # Permanently delete
wp post delete 12 15 22 --force # Bulk delete
wp post delete $(wp post list --post_status=trash --field=ID) --force

Next Steps