AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

SQL query to delete posts

3 Posts
2 Users
0 Reactions
125 Views
Posts: 26
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@vasiliy)
Eminent Member
Joined: 8 years ago
[#72950]

Hi!

What SQL query should I run to the database to delete posts in specific forums? The control panel freezes due to the large number of posts.


2 Replies
Posts: 26
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@vasiliy)
Eminent Member
Joined: 8 years ago
DELETE FROM `wpforo_posts` 
WHERE `topicid` IN (
    SELECT `topicid` FROM (
        SELECT `topicid` FROM `wpforo_topics` WHERE `forumid` IN (1, 2, 3)
    ) AS temp_table
);

DELETE FROM `wpforo_topics` 
WHERE `forumid` IN (1, 2, 3);

DELETE FROM `wpforo_forums` 
WHERE `forumid` IN (1, 2, 3);

Can I use this one?


Reply
Robert
Posts: 10778
Admin
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@robert)
Support Team
Joined: 4 months ago

Hi vasiliy,

Running a direct SQL query is a solid approach to handle bulk deletions efficiently. Here's a query structure that should work well for your situation:

DELETE FROM `wpforo_posts` WHERE `topicid` IN ( SELECT `topicid` FROM ( SELECT `topicid` FROM `wpforo_topics` WHERE `forumid` IN (1, 2, 3) ) AS temp_table ); 

DELETE FROM `wpforo_topics` WHERE `forumid` IN (1, 2, 3);

This approach works in stages: first, it deletes all posts from the specified forums (identified by their forum IDs), and then it deletes the topics themselves.

IMPORTANT:
The key thing here is to replace the forum IDs (1, 2, 3 in two places) with the actual IDs of the forums where you want to delete posts. You can adjust the IN clause to include as many or as few forum IDs as needed.

Safety Tip: Before running this query on your live database, I'd strongly recommend backing up your database first. Direct SQL queries can't be undone, so having a backup gives you peace of mind. Also, consider testing the query on a staging environment if you have one available.

Once you've identified the correct forum IDs and backed up your data, you can run this through your database management tool (like phpMyAdmin or your hosting provider's database interface). This should be much faster than using the control panel. 


Reply
Share: