Search bar for only blog page

Solved
Highlighted
Tourist
8 0 3

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?

0 Likes
Highlighted
Shopify Partner
2719 594 736

Hey @las1,

Try the following code.

<form action="/search" method="get" role="search">
    <input type="hidden" name="type" value="article" />
    <div class="input-group--underline">
      <input class="input-group__field" type="search" name="q" value="{{ search.terms | escape }}" placeholder="{{ 'general.search.placeholder' | t }}" aria-label="{{ 'general.search.placeholder' | t }}">
      <div class="input-group__btn">
        <button type="submit" class="btn btn--clear btn--square">
          {% include 'icon-search' %}
          <span class="icon__fallback-text">{{ 'general.search.submit' | t }}</span>
        </button>
      </div>
    </div>
  </form>
If helpful then please Like and Accept Solution.
Do you need custom changes on store ? Hire me.
Feel free to Contact me on dmw.webartisan@gmail.com
Follow us on Instagram @dmw.webartisan
1 Like
Highlighted
Tourist
8 0 3

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

2F4F73CC-8B0F-4681-987C-DF4D1DCD34B9.jpeg

0 Likes
Highlighted
Shopify Partner
2719 594 736

This is an accepted solution.

Hey @las1,

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.

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

 

 

If helpful then please Like and Accept Solution.
Do you need custom changes on store ? Hire me.
Feel free to Contact me on dmw.webartisan@gmail.com
Follow us on Instagram @dmw.webartisan
1 Like
Highlighted
Tourist
8 0 3

@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?

1 Like
Shopify Partner
2719 594 736

Hey @las1,

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

Hope you understand.

Thanks!

If helpful then please Like and Accept Solution.
Do you need custom changes on store ? Hire me.
Feel free to Contact me on dmw.webartisan@gmail.com
Follow us on Instagram @dmw.webartisan
1 Like
Highlighted
Tourist
8 0 3

@dmwwebartisan I understand. But thank you for the solution

1 Like