wp_delete_attachment


wp_delete_attachment ( $post_id, $force_delete = false )

Parameters:
  • (int) $post_id Attachment ID.
  • (bool) $force_delete Optional. Whether to bypass trash and force deletion. Default false.
Returns:
  • (WP_Post|false|null) Post data on success, false or null on failure.
Defined at:

Description

Trash or delete an attachment.

When an attachment is permanently deleted, the file will also be removed. Deletion removes all post meta fields, taxonomy, comments, etc. associated with the attachment (except the main post).

The attachment is moved to the trash instead of permanently deleted unless trash for media is disabled, item is already in the trash, or $force_delete is true.

Related Functions

wp_delete_attachment_files, wp_delete_comment, wp_insert_attachment, wp_get_attachment_url, wp_get_attachment_link

Top Google Results

User discussions

wpseek mobile