How can I make a search bar specifically for blog posts?

Hi,

i added this code on a page:

<form method="get" action="/search">
    <input type="text" name="q" />
    <input  type="submit" value="Search" />
</form>

But I want this search bar to only search for blog posts. How can I do this?

Hey @lcr1 ,

Try the following code.


@dmwwebartisan Hmm it’s not working. Or should I add it elsewhere? See photo.

Hey @lcr1 ,

Ahh, I thought you are working on the liquid file. I was not aware that you are putting this in the editor. In the editor, liquid code won’t work.

So let’s play with your code instead of liquid. Try the following code. This is your code. I just added a hidden input box there to pass the value article.


@dmwwebartisan Hehe, this worked perfect :))

Do you also know if it’s possible to do: no result then return and try again?
Or is that a bit more complex?

Hey @lcr1 ,

Well, that we can’t do with HTML. We must use liquid or do some coding for that. :slightly_smiling_face:

Hope you understand.

Thanks!

@dmwwebartisan I understand. But thank you for the solution :slightly_smiling_face:

not working for me i am still getting collections and products in my search result.

Just found this thread, I am not clear where to add this code for a blog search bar, my blog is displayed at. the bottom of my home page

Hey,

maybe interesting for others, who check this thread. We have developed an app for blog search. You can actually define your own filter groups, which allow you to add tagging filter system and a blog search. Within the blog search you can set featured articles as well. Maybe this helps others. There is a 7 days free trial, so you can test it, before using it. Ahoi Apps Blog Filter & Search

It seems like the code sample posted as the solution is hidden / removed?

Our experience so far has seen a few other edge cases that a simple code might not be able to cover. For example, dealing with multiple blogs, no search results, duplicated results or even the occasional maintenance due to Shopify’s API update.

If you do have a lot of high converting blog posts, and are not comfortable with code; I would recommend you implement blog search using a Shopify app instead.

Disclosure, we run a blog search and filter app that is battle tested since 2020.

image