WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm sorting out a long-neglected wordpress.org blog. It has over 100,000 pieces of trackback spam. How can I remove them all?

share|improve this question
up vote 2 down vote accepted

To make this more WP-ish:

function wpse_delete_trackbacks()
    global $wpdb;

    $wpdb->query( $wpdb->prepare(
            DELETE FROM %s WHERE `comment_type` = 'trackback'
    ) );
share|improve this answer
Your quotes around trackback need fixing, it's too minor an edit for me to perform! – fredley Apr 26 '12 at 13:08
@fredley »it's too minor an edit for me to perform« = ?? – kaiser Apr 26 '12 at 13:09
I don't have edit privileges, so my edits need to be at least 6 chars :-) – fredley Apr 26 '12 at 13:10
Ah, ok. You could simply add a comment // Make the query safer: Use prepare ;) Or you could add a check if there´re any trackbacks and in this case, abort and output a message. Anyway: fixed it. – kaiser Apr 26 '12 at 13:11

I gave up on finding an elegant solution and just used a MySQL sledgehammer to banish the spam:

DELETE FROM `wp_comments` WHERE `comment_type`="trackback"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.