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:

  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! Your category has been wikified :tada:


It can be used in #wiki (tag)?

Hi matenauta :slight_smile:

Yes, it would be possible by using the logic here:

Example (tested and working):

tag = Tag.find_by_name("design")
topics_id = Topic.joins(:topic_tags).where("topic_tags.tag_id = ?",
Post.where(topic_id: topics_id, post_number: 1).update_all(wiki: true)