php – wp_delete_comment takes two tries to delete – then deletes all comments


I’m trying to add a button to my comments that allows a user to delete them.

I have a form declared like so:

<form method="post">
  <input type="submit" name="btn-delete" value="try-delete">

and above it the following php:

  if (isset($_POST["btn-delete"])) {
    wp_delete_comment(get_comment_ID(), true);

Note this is in my comments.php, and I use the standard API for looping through the comments.

When I click on the button (from the input tag), it reloads the page and does nothing. If I click it again, it deletes all of the comments on the page, rather than just the one comment. How can I fix this?

Thanks in advance.

Nicolas Gimelli 8 months 2022-05-31T11:49:01-05:00 0 Answers 0 views 0

Leave an answer