Function Reference/wp delete post
Languages:
English •
Русский •
日本語 •
Türkçe •
(Add your language)
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 relationships between the post and taxonomy terms.
Usage
<?php wp_delete_post( $postid, $force_delete ); ?>
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 and a random wpdb object on success.
Examples
Delete Post
Deleting WP default post "Hello World" which ID is '1'.
<?php wp_delete_post(1); ?>
Notes
- wp_delete_post() automatically reverts to wp_trash_post() if $force_delete is false, the post_type of $postid is page or post, $postid is not already in the trash and if that trash feature enabled (which it it is by default).
- 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 $wpdb: (object) wpdb
- Uses global $wp_rewrite: (object) WP_Rewrite
Change Log
Since: 1.0.0
Source File
wp_delete_post() is located in wp-includes/post.php.
Related
Post, Page, Attachment and Bookmarks Functions: wp_trash_post(), wp_update_post(), wp_delete_attachment(), wp_insert_attachment(), wp_insert_post()