Recent searches
No recent searches
Default search to show articles only
Answered
Posted Jun 14, 2022
I need to be able to change the default setting in Guide search so that it shows articles only, rather than articles and community posts. I don't want to hide community comments completely, just change the default results. Is there a way to get this so that users can still select to include community posts using the left-hand menu?
This is the same a Jeff S' question here. Support also mentioned it may need coding, so any help with what I'd need to add would be greatly appreciated!
0
17
17 comments
Erica Girges
It does require a bit of custom JS code. You'll want to take a look at the Help Center templating cookbook to get familiar with how to edit code within your Guide theme. This post also shows a bit of a demonstration on one way to achieve it.
Hope this helps!
Erica
0
Ifra Saqlain
Hi Gwyn Mabo :)
Copy and paste the given JS code to your script.js file:
Thanks
Team
0
Gwyn Mabo
Thank you so much, Ifra! Which line would I paste this code into or does it not matter too much?
0
Ifra Saqlain
Just copy the script code and paste it at bottom area to script.js file.
Screenshot:
Add template name to the search results file:
Copy the jquery CDN and paste it to the document_head.hbs file.
0
Erica Girges
0
Ifra Saqlain
😊️
0
Gwyn Mabo
Hi Ifra, I've applied the code as instructed, but it hasn't changed the search results format at all. Is there anything else I've missed?
0
Ifra Saqlain
@Gwyn Mabo, it's working for me, may be classes are different or something else. Can you share your URL of your HC?
0
Gwyn Mabo
Hi Ifra, I haven't edited the code on my live site, but a draft theme.
0
Ifra Saqlain
If you didn't add the code in your live site then how can you get any kind of output for live as you want?
You added in your draft theme then you can see the output in your draft theme search results page not in your live site.
0
Gwyn Mabo
Hi Ifra, I wasn't using the live site to test it, I was using the preview version of the draft theme. I assumed (like it does with other changes viewed using the preview) that this would work.
0
Ifra Saqlain
Hi Gwyn Mabo,
Test like this:-
Search "What" in the search-bar.
Only articles would be list with what string not community posts.
But when you remove the added code (Given above) from script file then all posts would be shown (If exist with the 'what' string) as default results on the page.
0
Gwyn Mabo
Hi Ifra, that is exactly what I did, and it did not work I'm afraid.
0
Ifra Saqlain
Hi Gwyn :), is there any way I can see the bug in your theme?, then I can provide some solution.
0
Gwyn Mabo
Hi Ifra, more than happy for you to help out, what do I need to do?
0
Ifra Saqlain
You should set your draft mode theme live, then share the URL here.
0
Jonathan
Instead of suggesting that we do custom javascript is it possible zendesk make a change to the search helper?
https://developer.zendesk.com/api-reference/help_center/help-center-templates/helpers/#search-helper
providing a filter option for either : unified, knowledge_base, or community
linking the user directly to http://<domain>/hc/en-us/search?filter_by=<chosen_filter>&query=<query>" so we can default to showing knowledge_base articles but easily provide the option for community as well.
A workaround I found was to create the following in order to override the searches default functionality.
0