# 커스텀 필드 기준으로 주제 가져오기?

**URL:** <https://meta.discourse.org/t/retrieve-topics-based-on-custom-field/199879>\
**Category:** Development\
**Created:** [8월 9, 2021, 9:39오후 UTC](https://meta.discourse.org/t/retrieve-topics-based-on-custom-field/199879 "2021-08-09T21:39:27Z")\
**Posts on this page:** 1\
**Showing post:** 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:** [8월 9, 2021, 9:39오후 UTC](https://meta.discourse.org/t/retrieve-topics-based-on-custom-field/199879/1 "2021-08-09T21:39:27Z")

</div>

@angus님의 [매우 유용한 가이드](https://meta.discourse.org/t/how-to-add-custom-fields-to-models/184485)를 참고하여 토픽과 그룹에 커스텀 필드를 추가하는 데 성공했습니다.

커스텀 필드를 성공적으로 추가한 후, **해당 커스텀 필드를 기반으로 항목을 검색** 하는 (효율적인) 방법이 있을까요?

예를 들어, 토픽에 `fun_level`이라는 커스텀 필드를 추가했다고 가정해 보겠습니다. 그러면 이제 제 플러그인을 통해 `topic.fun_level`(문자열) 필드가 추가된 상태입니다.

이제 `fun_level`이 "super-duper-fun"인 모든 토픽의 목록을 검색하고 표시하고 싶습니다.

어떻게 해야 할까요?

* * *

특정 태그가 있는 모든 토픽을 검색하려면 `ajax('/tags/tag-name.json').then(function(result))...`와 같은 방법을 사용할 수 있습니다. [이 설명 게시물](https://meta.discourse.org/t/how-to-add-a-featured-topic-list-to-your-discourse-homepage/132949)에서 사용된 방식과 같습니다.

방금 만든 커스텀 필드의 경우, 이 방법은 사용할 수 없을 것 같습니다(생각하기에). 이는 커스텀 필드를 위한 컨트롤러(예: `fun_level` 컨트롤러)를 생성해야 하기 때문입니다. 이 컨트롤러에는 `:fun_level` 파라미터 값과 `fun_level`이 일치하는 모든 토픽을 검색하는 show 메서드가 포함되어야 합니다.

더 직관적인 방법이 있을 것 같은데, 맞나요?

---

_[View the full topic](https://meta.discourse.org/t/retrieve-topics-based-on-custom-field/199879)._
