Home » Functions » wp_delete_post

Function Name: wp_delete_post

If you’re working with WordPress, at some point you may need to delete a post from the database. In such cases, the wp_delete_post function can be used to delete a post and all its associated data.

This function takes a single parameter, which is the ID of the post to be deleted. The function then removes the post from the database and all its associated metadata, revisions, and attachments.

It’s important to note that wp_delete_post will also remove all comments associated with the post. If you want to keep the comments, you can set the $force_delete parameter to false, and the comments will be moved to the trash instead.

Example Usage Code:

// delete a post with ID 123 wp_delete_post(123);

// delete a post with ID 456 and all its associated comments wp_delete_post(456, true);

Learn More on WordPress.org

WordPress snippets using the wp_delete_post function

Register an account to save your snippets or go Pro to get more features.