From MattWiki
Jump to: navigation, search

Permanently remove deleted posts and topics

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;
UPDATE bb_forums SET topics = 0;

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