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?


To make this more WP-ish:

function wpse_delete_trackbacks()
    global $wpdb;

    $wpdb->query( $wpdb->prepare(
            DELETE FROM %s WHERE `comment_type` = 'trackback'
    ) );
  • 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
  • 1
    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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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