Codex

Function Reference/wp delete post

Contents

Description

Removes a post, attachment, or page.

When the post and page goes, everything that is tied to it is deleted also. This includes comments, post meta fields, and terms associated with the post.

Usage

<?php wp_delete_post$postid$force_delete false ?>

Parameters

$postid
(integer) (optional) Post ID.
Default: 0
$force_delete
(bool) (optional) Whether to bypass trash and force deletion (added in WordPress 2.9).
Default: false

Return Values

(mixed) 
False on failure.

Examples

Delete Post

Deleting WP default post "Hello World" which ID is '1'.

<?php wp_delete_post(1); ?>

Notes

  • Uses: do_action() on 'delete_post' before deletion unless post type is 'attachment'.
  • Uses: do_action() on 'deleted_post' after deletion unless post type is 'attachment'.
  • Uses: wp_delete_attachment() if post type is 'attachment'.
  • Uses global: (object) $wpdb
  • Uses global: (object) $wp_rewrite

Change Log

Since: 1.0.0

Source File

wp_delete_post() is located in wp-includes/post.php.

Related

wp_update_post(), wp_delete_attachment(), wp_get_attachment_url(), wp_insert_attachment(), wp_insert_post()