(Add your language)
Removes or trashes 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.
<?php wp_delete_post( $postid, $force_delete ); ?>
- (integer) (optional) Post ID.
- Default: 0
- (bool) (optional) Whether to bypass trash and force deletion (added in WordPress 2.9).
- Default: false
- The post object (if it was deleted or moved to the trash successfully) or false (failure). If the post was moved to to the trash, $post represents its new state; if it was deleted, $post represents its state before deletion.
Deleting WP default post "Hello World" which ID is '1'.
<?php wp_delete_post(1); ?>
- 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
wp_delete_post() is located in
Post, Page, Attachment and Bookmarks Functions: wp_trash_post(), wp_update_post(), wp_delete_attachment(), wp_insert_attachment(), wp_insert_post()