# Getting Category's custom field value from Topic

**URL:** <https://meta.discourse.org/t/getting-categorys-custom-field-value-from-topic/56571>\
**Category:** Development\
**Created:** [January 30, 2017, 7:59am UTC](https://meta.discourse.org/t/getting-categorys-custom-field-value-from-topic/56571 "2017-01-30T07:59:08Z")\
**Posts on this page:** 5\
**Page:** 1

## AI-generated summary

[Janno_Liivak](/t/-/56571/1) is developing a plugin to access a custom category field (`enable_bump_topic`) from a Topic model. They report that the `custom_fields` property returns `undefined` when navigating directly to a Topic, only working correctly after visiting the Category's edit form first, suggesting the data is not loaded by default. [Falco](/t/-/56571/2) advises that the custom field must be explicitly added to the serializer for the relevant page or fetched via an additional API request. When [Janno_Liivak](/t/-/56571/3) requests an example of adding a field to a serializer, [Falco](/t/-/56571/4) provides a reference to the `discourse-signatures` plugin [code](/t/-/56571/4), explaining that they need to implement a similar modification for the topic serializer. [Janno_Liivak](/t/-/56571/5) confirms this guidance helps them progress with the implementation.

<div class="post-metadata">

**Author:** ![Janno\_Liivak](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/janno_liivak/32/352215_2.png) [@Janno\_Liivak](https://meta.discourse.org/u/Janno_Liivak)\
**Post date:** [January 30, 2017, 7:59am UTC](https://meta.discourse.org/t/getting-categorys-custom-field-value-from-topic/56571/1 "2017-01-30T07:59:08Z")

</div>

I have created custom category field enable\_bump\_topic (by example of @SamSaffron’s discourse-solved plugin). But I don’t seem to get how could I access this custom field when on Topic. I created canBump computed property for Topic ([discourse-bump-topic/assets/javascripts/discourse/initializers/extend-topic-for-bump-button.js.es6 at master · jannolii/discourse-bump-topic · GitHub](https://github.com/jannolii/discourse-bump-topic/blob/master/assets/javascripts/discourse/initializers/extend-topic-for-bump-button.js.es6)) but I only get value out from Category’s custom field when I first visit Category and open Edit form and then go to this Categroy’s topic. If I go directly to Topic I get undefined when try to access custom\_fields. It’s like custom\_fields doesn’t exist before I go and look at the Category settings.

What am I missing? What am I not getting?

My (still very raw) project: [GitHub - jannolii/discourse-bump-topic · GitHub](https://github.com/jannolii/discourse-bump-topic)

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [January 30, 2017, 1:54pm UTC](https://meta.discourse.org/t/getting-categorys-custom-field-value-from-topic/56571/2 "2017-01-30T13:54:14Z")

</div>

You need to add it to the serializer of the page you want it to be, or make an additional request to an endpoint that will give you this value.

---

<div class="post-metadata">

**Author:** ![Janno\_Liivak](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/janno_liivak/32/352215_2.png) [@Janno\_Liivak](https://meta.discourse.org/u/Janno_Liivak)\
**Post date:** [January 30, 2017, 2:33pm UTC](https://meta.discourse.org/t/getting-categorys-custom-field-value-from-topic/56571/3 "2017-01-30T14:33:34Z")

</div>

Thanks. Could there be an example where custom field is being added to a serializer? Quick scan didn’t reveal such thing being used in some popular plugins

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [January 30, 2017, 2:36pm UTC](https://meta.discourse.org/t/getting-categorys-custom-field-value-from-topic/56571/4 "2017-01-30T14:36:03Z")

</div>

> <https://github.com/xfalcox/discourse-signatures/blob/master/plugin.rb#L20-L26>

Here code it’s adding a new field to the post serializer. You need something similar, but adding a new field to the topic serializer I think.

---

<div class="post-metadata">

**Author:** ![Janno\_Liivak](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/janno_liivak/32/352215_2.png) [@Janno\_Liivak](https://meta.discourse.org/u/Janno_Liivak)\
**Post date:** [January 30, 2017, 4:42pm UTC](https://meta.discourse.org/t/getting-categorys-custom-field-value-from-topic/56571/5 "2017-01-30T16:42:24Z")

</div>

Thanks a lot! Now I’m starting to get somewhere 😉
