The wp_delete_post() WordPress function Updated on May 27, 2021 by Jeff Matson 0 Minutes, 59 Seconds to Read At times, you may need to delete a post using a WordPress plugin. For example, if you had a calendar system that created posts for events, and the event was canceled or happened in the past, the ability to automatically delete posts can be quite useful. In this article, we will show you how to easily delete WordPress posts using the wp_delete_post() function. For more information on creating WordPress plugins, review our article on creating your first WordPress plugin Basic usage <?php wp_delete_post( $postid, $force_delete ); ?> Parameters $postid: This parameter allows you to define the post that will be deleted and accepts the post ID. For example, if you want to delete the post with ID 5, set the parameter to 5. $force_delete: This optional parameter allows you to bypass the trash and permanently delete the post. It is accepts a boolean (true of false) and defaults to false. Example <?php wp_delete_post(5); ?> In this example, we are simply calling the wp_delete_post() function to delete the post with ID 5. References For more information on the wp_delete_post() function, you may review the wp_delete_post() WordPress Codex page. Share this Article Related Articles How to Create and Edit Pages and Posts in WordPress What is the Difference Between Pages and Posts in WordPress How to Add Videos to WordPress How to Create and Add a Logo To WordPress How to Use a Custom Paypal Button in Your Website How to Track WordPress Vulnerabilities With WPScan How to Redirect WordPress Posts After Changing Permalinks W3 Total Cache – Guide to WordPress Caching How to Globally Change the Font in WordPress Create a Footer for WordPress