How to use wp_delete_post to delete post or pages

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.

<?php wp_delete_post( $postid, $force_delete ); ?>
$postidintigerarticle ID0no
$force_deletebooleanskip recycle bin and delete permanentlyfalseno

(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.

Delete the default WordPress post with ID 1 and title “Hello World”:

<?php wp_delete_post(1); ?>

Was this post helpful?

Leave a Reply