Is there a way to delete a Post From Front-End and it’s attachments permanently? This is a snippet that moves the post to the trash can, but it doesn’t remove attached images (they remain on the server) and it doesn’t remove the post permanently? Could someone please help?
<?php
$url = get_bloginfo('url');
if (current_user_can('edit_post', $post->ID)){
echo '<a class="delete-post" href="';
echo wp_nonce_url("$url/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post-
>ID);
echo '">Delete post</a>';
}
?>
Try:
You can decide when to empty the WordPress trash by adding this code to the wp-config.php file in your WordPress root directory.
The 1 in the code signifies you want to empty the trash everyday. If you set to 0, the trash functionality will be disabled.
Finally, WordPress doesn’t delete images when they are no longer attached to a page. See this ticket for an explanation: http://core.trac.wordpress.org/ticket/12108 Gist being that
If you want to go against that rational, you can add this to your functions.php:
Also see Upload Janitor if you want to go the plug-in route for deleting unattached images.
There is no need to call the database manually, this works too: