Wp post delete (WP-CLI): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 103: Regel 103:
 
</pre>
 
</pre>
  
And now use this to delete it:
+
And now use this to delete it. The flag <code>--force</code> is needed, as there is no ''trash'' repository for attachments:
  
 
<pre>
 
<pre>
wp post list --post_type="attachment" --name="formulier-voor-herroeping" --field=ID | xargs -n1 wp post delete
+
wp post list --post_type="attachment" --name="formulier-voor-herroeping" --field=ID | xargs -n1 wp post delete --force
 
</pre>
 
</pre>
  

Versie van 20 sep 2022 13:17

$ 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.

Delete a specific attachment

I want to delete the attachment called formulier-voor-herroeping from a site.

Let's first retrieve its ID:

wp post list --post_type="attachment" --name="formulier-voor-herroeping" --field=ID

And now use this to delete it. The flag --force is needed, as there is no trash repository for attachments:

wp post list --post_type="attachment" --name="formulier-voor-herroeping" --field=ID | xargs -n1 wp post delete --force

See also