How to delete all posts for an admin

OK, so you don’t actually about admin status here. Your goal is removal of posts? Suggestion for the future, let us know what you’re end goal is, not the current step you think will help you get there.

I don’t believe we have a rake task to delete all posts by a specific user. Let me test some things, I’ll get back to you.

OK. The following will allow you to delete all the posts by a user. You’ll need server access.

  1. SSH into the server where Discourse is running.
  2. Access the rails console of your Discourse instance.
    cd /var/www/discourse
    sudo ./launcher enter app
    rails c
    
  3. Obtain the id of the user you want to delete, then destroy all posts by the user. This assumes the username is newsbot, if it isn’t, be sure to edit the command,
    id = User.find_by_username('newsbot').id
    Post.where(user_id: id).each do |p|
      PostDestroyer.new(Discourse.system_user, p).destroy  
    end;