Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_delete_post

Function Description:

Trashes or deletes a post or page.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Delete a specific post by ID
$post_id = 123;
wp_delete_post($post_id, true);
// Example 2: Delete a post and move it to trash instead of permanently deleting it
$post_id = 456;
wp_delete_post($post_id);
// Example 3: Check if the post exists before deleting it
$post_id = 789;
if (get_post_status($post_id)) {
   wp_delete_post($post_id, true);
} else {
   echo 'Post does not exist';
}