Convert all existing topics in category to wikis

Discourse categories have a “Make new topics wikis by default” setting that can be enabled to automatically ensure that each new topic created within that category is a wiki from the start.

If you happen to enable this setting after the category has existed for some time, you may wish to make all of the old topics wikis as well. Here’s what you can do:

  1. Make sure you backup your site just in case something goes wrong.

  2. Get the id of the relevant category from the category’s URL. For example, the category id of this link to our #documentation category is 10: https://meta.discourse.org/c/documentation/10

  3. SSH into your server and run each of the following commands, replacing <MY_CATEGORY_ID> with the actual id:

    cd /var/discourse
    ./launcher enter app 
    rails c
    tids = Topic.where(category_id: <MY_CATEGORY_ID>).pluck(:id)
    Post.where(topic_id: tids, post_number: 1).update_all(wiki: true)
    

That’s it! You category has been wikified :tada:

12 Likes