Delete

Advertisement

With the help of wp post delete command you can:

  • Delete post
  • Delete page
  • Delete custom post type

Enough?

Nope, As you know after post, page, custom post type delete it goes to the trash.

With the help of wp post delete we can even delete them from trash.

Easy. right?

Let see how to use the wp post delete command.

Syntax Syntax

Below is the syntax of the wp post delete command:

wp post delete <id> [--force] [--defer-term-counting]

Here,

  • <id> – (Required) Is the post, page or custom post type ID.
  • [–force] – (Optional) Is the flag to delete the post, page, or custom post type even from trash
  • [–defer-term-counting] – (Optional) Is the flag to recalculate term count in batch, for a performance boost

NOTE: Here the characters are used for:

  • <> – Means this is a required parameter.
  • [] – Means its optional. Not required.

Top ↑

Usage Usage

Simply add the post, page, or custom post type ID as:

wp post delete 5

Let’s check few other examples:

How to delete the post permanently (from trash too)? How to delete the post permanently (from trash too)?

wp post delete 7 --force

Above command delete the post ID 7 permanently. It’ll not display in the trash list.

Top ↑

How to delete all the pages? How to delete all the pages?

wp post delete $(wp post list --post_type='page' --format=ids)

With the use of the above command all pages are deleted. You can see them in the trash list.

Here,

The wp post list command is used with –format flag which returns the IDs of all pages.

In short, From the above command, we technically use two different commands:

  • wp post delete – Delete the pages by ID.
  • $(wp post list –post_type=’page’ –format=ids) – This command return the IDs of all pages

Top ↑

How to delete all the pages permanently? How to delete all the pages permanently?

By simply adding the –force flag all pages will delete permanently.

wp post delete $(wp post list --post_type='page' --format=ids) --force

With the use of the above command all pages are deleted. You can see them in the trash list.

Leave a Reply