Permanently remove deleted posts and topics in bbPress

Permanently removing deleted posts and topics in bbPress can be cumbersome. bbPress does not provide a decent way to completely remove deleted content from the database. I am not sure why… In my case, these posts mostly contain spam and there is absolutely no reason to keep them in the database any more. As it usually happens when I try to administer bbPress, I ended up executing SQL queries at the MySQL prompt. I hereby publish these SQL statements.

First delete all posts in deleted topics:

DELETE FROM bb_posts WHERE post_id IN (
    SELECT post_id FROM (
        SELECT DISTINCT(p.post_id)
        FROM bb_posts AS p LEFT JOIN bb_topics AS t ON p.topic_id=t.topic_id
        WHERE t.topic_status=1
    ) AS bb_posts_in_deleted_topics

Then remove all deleted posts:

DELETE FROM bb_posts WHERE post_status=1;

Finally, remove all deleted topics:

DELETE FROM bb_topics WHERE topic_status=1;

In the bbPress administration panel, you can now use the “Tools” section to recount posts.

Permanently remove deleted posts and topics in bbPress by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Permissions beyond the scope of this license may be available at Licensing Information.
Copyright © 2010 - Some Rights Reserved

George Notaras avatar

About George Notaras

George Notaras is the editor of G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.

One response on “Permanently remove deleted posts and topics in bbPress

  1. Pothi Kalimuthu Permalink →

    Used it on bbPress 1.x. Wanted to remove deleted posts and topics, before migrating to the latest version. Worked without any issues. Thanks for sharing!