wp_delete_post function allows us to permanently delete posts, pages, attachments. When a post is deleted, all the associated content will also be deleted, this includes the comments, custom fields, and category entries.
Instructions
<?php wp_delete_post( $postid, $force_delete ); ?>
Parameter
PARAMETER | TYPE | DESCRIPTION | DEFAULT | REQUIRED |
$postid | intiger | article ID | no | |
$force_delete | boolean | skip recycle bin and delete permanently | false | no |
Return value
(mixed) The post object (if deleted or moved to the recycle bin is successful), it returns false when it fails. If the post is moved to the recycle bin, the $post object is the new state of the post. If it is permanently deleted, $post is the one before the post is deleted.
Examples
Delete the default WordPress post with ID 1 and title “Hello World”:
<?php wp_delete_post(1); ?>
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂