EDIT: Having looked into api.addDiscoveryQueryParam more, I think I now get the general idea:
I want to programmatically retrieve all topics with the custom field fun_level = super-duper-fun
. I think perhaps a controller method could do it? (still figuring that out).
An alternative is to do a search with ajax("/search") where I am searching all topics based on the custom field fun_level=super-duper-fun
. But creating the custom field is not enough to enable this. I need to make the custom field fun_level
one of the fields you can search against (just like you can search again certain categories, tags, etc), and that is not done automatically.
In some way, api.addDiscoveryQueryParam
in a js file mixed with TopicQuery
in plugin.rb
is required to do that. But, tbh, I just haven’t gotten it to work. I’ve seen some plugins that use these methods, but I haven’t been able to sort out how they “bring it home”. I think some additional code is required, but I haven’t found it yet.
How you go from these methods to actually having the custom field available as a search term?
Earlier Reply
Thanks, @angus. To clarify the goal is not to have users manually enter search values in the search box. The goal is to go to programmatically retrieve topics based on a certain custom field. For example, the user would go to the page /fun_levels/super-duper-fun
and load all topics where the field fun_level
= ‘super-duper-fun’.
Is api.addDiscoveryQueryParam
for that purpose?
Looking at examples like here, I’m not sure how addDiscoveryQueryParam works to actually retrieve the topics (I don’t think calling that method returns results that I can parse).
Maybe it is for potentially allowing the user to manually search by the term in the search box? That’s not the situation I am aiming at. (I could definitely be missing something).
I mentioned using ajax("/search…") earlier as that’s the best I’ve come up with so far to return topics, but I am wondering if there is a more efficient way to do it, even including setting up a model and controller method so show topics automatically, like how tags/:tag-name does it (that’s more complex, so I’m hoping to avoid it, but if it’s the best way I’ll consider it).