# Custom Fields for Groups?

**URL:** https://meta.discourse.org/t/custom-fields-for-groups/153580
**Category:** Development
**Tags:** groups
**Created:** [June 2, 2020, 2:25pm UTC](https://meta.discourse.org/t/custom-fields-for-groups/153580 "2020-06-02T14:25:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [June 2, 2020, 2:25pm UTC](https://meta.discourse.org/t/custom-fields-for-groups/153580/1 "2020-06-02T14:25:35Z")

</div>

Is it possible to create custom fields for Groups, just like we can add (and retrieve) custom fields for Users?

I have seen mention of this as a request here and there (like [here](https://meta.discourse.org/t/customize-group-profile/26761)).

If it’s not built into Discourse right now (it seems to me it’s not), is there a way to mimic this behavior?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [June 2, 2020, 2:28pm UTC](https://meta.discourse.org/t/custom-fields-for-groups/153580/2 "2020-06-02T14:28:28Z")

</div>

You can do this in a plugin.

---

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [June 2, 2020, 2:29pm UTC](https://meta.discourse.org/t/custom-fields-for-groups/153580/3 "2020-06-02T14:29:48Z")

</div>

How would you do it?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [June 2, 2020, 2:31pm UTC](https://meta.discourse.org/t/custom-fields-for-groups/153580/4 "2020-06-02T14:31:18Z")

</div>

eg, in plugin.rb:

```plaintext
Group.register_custom_field_type('my_attribute', :boolean)
Group.preloaded_custom_fields << "my_attribute" if Group.respond_to? :preloaded_custom_fields

```

---

<div class="post-metadata">

### Author: ![AquaL1te](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aqual1te/32/201966_2.png) [@AquaL1te](https://meta.discourse.org/u/AquaL1te)
#### Post date: [August 6, 2022, 7:57am UTC](https://meta.discourse.org/t/custom-fields-for-groups/153580/5 "2022-08-06T07:57:21Z")

</div>

This would be awesome indeed. I would like to add a custom location field to groups so that I can use the g.json output to generate a map based on the groups and amount of members.

I’ll experiment a bit with your suggestion. Do you also have some more info about how to use this snippet? Can it be used in a custom theme component? How would someone do that? Has anyone already used it?

---

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [August 6, 2022, 2:03pm UTC](https://meta.discourse.org/t/custom-fields-for-groups/153580/6 "2022-08-06T14:03:13Z")

</div>

To add custom fields to models (topics, categories, groups), the following topic from @angus really lays it out as well as you’re likely to find:

> [@How to add custom fields to models](https://meta.discourse.org/t/how-to-add-custom-fields-to-models/184485):
>
> This is a collection of education plugins that demonstrate how to add a custom field to different models in Discourse. They are intended as learning tools for those looking to learn how to build discourse plugins. [[GitHub-Mark] How to add a custom field to a topic](https://github.com/pavilionedu/discourse-topic-custom-fields)[[GitHub-Mark] How to add a custom field to a category](https://github.com/pavilionedu/discourse-category-custom-fields)Who they’re for These plugins are for people looking to learn more about creating Discourse plugins. Before you start working with these plugins, you should complete the [beginner…](https://meta.discourse.org/t/beginners-guide-to-creating-discourse-plugins/30515)

He has put together some sample code specific to topics and categories - I believe the code translates generally well for adding custom fields to groups as well.

This post from me on that topic lays out how I’ve used the resource that Angus has put together:

> [@How to add custom fields to models](https://meta.discourse.org/t/how-to-add-custom-fields-to-models/184485/7):
>
> That is fantastic, @angus. Thank you very much. A video is always nice–I’m all for making things as straightforward as possible, but I don’t think it’s required to get the key value from these resources that @angus has put together. These resources give the code that you need to accomplish the specific goal the resource is about (having a working topic custom field or a category custom field). A video would probably just be @angus or someone else talking through how to implement the resource,…
