Skip to content

Instantly share code, notes, and snippets.

@webdados
Created February 5, 2020 09:22
Show Gist options
  • Save webdados/f82bddb3ac5f255611e862a3ac0291a9 to your computer and use it in GitHub Desktop.
Save webdados/f82bddb3ac5f255611e862a3ac0291a9 to your computer and use it in GitHub Desktop.
Delete all comments from a WordPress post
<?php
/*
- Save this PHP file to the root of your WordPress website
- Log in as Administrator
- Change the post ID on line 13
- Call the PHP file it directly on your borwser
*/
require('./wp-load.php');
if ( current_user_can( 'manage_options' ) ) {
if ( $comments = get_comments( array( 'post_id' => 16057 ) ) ) {
foreach ( $comments as $comment ) {
echo '<p>Deleting comment '.$comment->comment_ID.'</p>';
wp_delete_comment( $comment->comment_ID, true );
}
} else {
echo '<p>No comments found</p>';
}
} else {
echo '<p>Not allowed</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment