---
title: "The wp_delete_post() WordPress function"
description: "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..."
url: https://www.inmotionhosting.com/support/edu/wordpress/wp-delete-post-wordpress-function/
date: 2014-07-09
modified: 2021-05-27
author: "Jeff Matson"
categories: ["WordPress Hosting", "WordPress Tutorials"]
type: post
lang: en
---

# The wp_delete_post() WordPress function

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](https://www.inmotionhosting.com/support/edu/wordpress/plugins/create-a-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](https://codex.wordpress.org/Function_Reference/wp_delete_post).
