Created
February 5, 2020 09:22
-
-
Save webdados/f82bddb3ac5f255611e862a3ac0291a9 to your computer and use it in GitHub Desktop.
Delete all comments from a WordPress post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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