Wp post delete (WP-CLI)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
$ wp help post delete

NAME

  wp post delete

DESCRIPTION

  Deletes an existing post.

SYNOPSIS

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

OPTIONS

  <id>...
    One or more IDs of posts to delete.

  [--force]
    Skip the trash bin.

  [--defer-term-counting]
    Recalculate term count in batch, for a performance boost.

EXAMPLES

    # Delete post skipping trash
    $ wp post delete 123 --force
    Success: Deleted post 123.

    # Delete all pages
    $ wp post delete $(wp post list --post_type='page' --format=ids)
    Success: Trashed post 1164.
    Success: Trashed post 1186.

    # Delete all posts in the trash
    $ wp post delete $(wp post list --post_status=trash --format=ids)
    Success: Deleted post 1268.
    Success: Deleted post 1294.

Voorbeeld

##############################################################
# Verwijder sample pagina
##############################################################
#
wp post list
wp post delete 1

Output:

+----+--------------+-------------+---------------------+-------------+
| ID | post_title   | post_name   | post_date           | post_status |
+----+--------------+-------------+---------------------+-------------+
| 1  | Hello world! | hello-world | 2017-12-02 11:37:28 | publish     |
+----+--------------+-------------+---------------------+-------------+
Success: Trashed post 1.

Nog een keer, maar nu echt:

##############################################################
# Verwijder sample pagina
##############################################################
#
wp post list --post_type="page"
wp post delete 2

Output:

+----+-------------+-------------+---------------------+-------------+
| ID | post_title  | post_name   | post_date           | post_status |
+----+-------------+-------------+---------------------+-------------+
| 2  | Sample Page | sample-page | 2017-12-02 11:37:28 | publish     |
+----+-------------+-------------+---------------------+-------------+
Success: Trashed post 2.

Verwijder alle producten

Toon de ID's van alle WooCommerce-producten: wp post list --post_type=product --field=ID. Hier lijkt geen limiet van bv. max. 100 rijen te gelden.

Zie ook