wp-content » themes » functions.php » 💡 How to use wp_delete_post to delete Posts or Pages

💡 How to use wp_delete_post to delete Posts 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 ); ?>
PARAMETERTYPEDESCRIPTIONDEFAULTREQUIRED
$postidintigerarticle IDno
$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); ?>
See also  How to change domain name for a WordPress website (5 ways)

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended