Retrieve Topics based on custom field?

When you’re dealing with topic lists the question is whether you extend the existing Discourse discovery structure, or whether you create your own, which changes the implementation. There are many related questions to what you’re looking to do which we’re skipping over here.

So if you’re not extending the discovery structure, you won’t be doing the first part of what I suggested above. You should still do the second part though, adding the custom filter to TopicQuery. You’ll also need a client side route with an ajax call to an endpoint mapped to the list_controller.rb. You can find the list controller routes in config/routes.rb by doing a search for list#.

You should use the same topic list endpoint Discourse discovery uses, as you’ll then get things like pagination (handled by load-on-scroll in the topic list component), permission handling and many other things out of the box.

So you’ll need

  1. plugin.rb containing the custom filter
  2. client side route file
  3. client side template
1 Like