Convert all existing topics in category to wikis

:bookmark: This guide explains how to convert all existing topics in a Discourse category to wikis.

:person_raising_hand: Required user level: Server administrator with SSH access

Discourse allows categories to have topics marked as wikis by default. This setting ensures that any new topic within the category automatically becomes a wiki.

However, if you’ve enabled this setting for a category that has already existed for some time, you may want to convert all pre-existing topics in that category to wikis as well.

Follow these steps if you wish to apply wiki status to older topics after enabling automatic wiki creation.

Convert topics to wikis

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

Last edited by @SaraDev 2024-10-30T23:14:13Z

Check documentPerform check on document:
15 Likes

It can be used in #wiki (tag)?

Hi matenauta :slight_smile:

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

https://meta.discourse.org/t/administrative-bulk-operations/118349#move-all-topics-with-a-specific-tag-to-a-single-category-15

Example (tested and working):

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