How to Disable Comments and Pingbacks in WordPress Using SQL
If your WordPress website receives a high volume of spam comments or you manage multiple sites where comments are not needed, you can quickly disable comments and pingbacks directly from the database. This method is especially useful when working on large sites, speeding up migrations, or when wp-admin is inaccessible.
What These SQL Commands Do
- Disable comments for all existing posts and pages
- Disable pingbacks & trackbacks for all existing posts
- Disable comments and pingbacks by default for all future posts
These changes are made directly in the WordPress database using phpMyAdmin or any MySQL tool with access to your site’s database.
SQL Commands to Disable Comments & Pingbacks
You can copy and paste the following commands into the SQL tab inside phpMyAdmin:
UPDATE wp_posts SET ping_status = 'closed';
UPDATE wp_posts SET comment_status = 'closed';
UPDATE wp_options SET default_ping_status = 'closed';
UPDATE wp_options SET default_comment_status = 'closed';
Important: If your WordPress installation uses a custom table prefix (e.g., wp3f7_posts), update the table names accordingly.
How to Run the SQL Commands (phpMyAdmin)
- Log in to cPanel.
- Open phpMyAdmin from the Databases section.
- Select your WordPress database from the left panel.
- Click the SQL tab at the top.
- Paste the SQL commands into the text box.
- Click Go to execute.
Once executed, comments and pingbacks will be disabled across all posts and pages.
Optional: Disable Comment Fields on the Front-End
Running the SQL commands disables comment functionality, but themes may still display the comment form. To fully hide it:
- Go to WordPress Admin → Settings → Discussion
- Uncheck:
- Allow people to submit comments on new posts
- Allow link notifications from other blogs (pingbacks and trackbacks)
Some themes also require you to disable comments in the theme options panel or via a custom child theme.
Re-Enabling Comments Later
If you change your mind later, you can reverse the settings by running:
UPDATE wp_posts SET comment_status = 'open';
UPDATE wp_posts SET ping_status = 'open';
UPDATE wp_options SET default_comment_status = 'open';
UPDATE wp_options SET default_ping_status = 'open';
This will restore normal WordPress comment functionality.