# Delete All Pingbacks and Trackbacks

> Run on demand to permanently delete every pingback and trackback stored as a comment, which on older blogs are often thousands of spammy rows nobody reads.

- Type: PHP
- Runs: On demand
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: comments, pingbacks, database
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/perf-delete-pingbacks/

## Code

```php
global $wpdb;

$wpide_ids     = $wpdb->get_col( "SELECT comment_ID FROM {$wpdb->comments} WHERE comment_type IN ('pingback','trackback') LIMIT 5000" );
$wpide_deleted = 0;

foreach ( $wpide_ids as $wpide_id ) {
    if ( wp_delete_comment( (int) $wpide_id, true ) ) {
        $wpide_deleted++;
    }
}

printf( 'Deleted %d pingback(s) and trackback(s).%s', $wpide_deleted, count( $wpide_ids ) === 5000 ? ' Run again to delete more.' : '' );
```

## Notes

Run it from the snippet editor; pair it with a snippet that disables pingbacks so new ones do not arrive.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Delete All Pingbacks and Trackbacks" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
