What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: How to search for articles in a specific blog only.

How to search for articles in a specific blog only.

ijw
Shopify Partner
11 0 2

I am looking for ways to modify my search form to search only for articles in a specific blog.

 

I have three blogs... Stories, Recipes, and Events.

 

I have a custom search form that is working to limit my search to articles only, I am looking for a way to augment the search form code to limit the form to only display articles from each specific blog. 

 

Changing the value to "article" works great, I need to further limit this search to specific blogs.

 

I do not have a link that I can share.

I am not interested in any paid plugins or hiring anyone, just looking for advice/guidance.

If it is not possible I'm open to that as well.

 

<form action="{{ routes.search_url }}">
  <input type="text"
    placeholder="Search"
    name="q"
    value="{{ search.terms | escape }}"
  />
  <input type="hidden" name="type" value="article" />
  <input type="hidden" name="options[prefix]" value="last" />
  <input type="submit" value="Search" />
</form>

 

Replies 7 (7)

NomtechSolution
Astronaut
1245 113 154

To modify your search form to search only for articles in a specific blog, you can add another hidden input field to specify the blog. Here's an example of how you can modify your existing search form code:

<form action="{{ routes.search_url }}">
  <input type="text"
    placeholder="Search"
    name="q"
    value="{{ search.terms | escape }}"
  />
  <input type="hidden" name="type" value="article" />
  <input type="hidden" name="options[prefix]" value="last" />
  <input type="hidden" name="blog" value="Stories" /> <!-- Specify the blog name here -->
  <input type="submit" value="Search" />
</form>

In the example above, I've added a new hidden input field called "blog" and set its value to "Stories" as an example. You can replace "Stories" with the specific blog you want to limit the search to, such as "Recipes" or "Events".

ijw
Shopify Partner
11 0 2

@NomtechSolution Thanks for your reply and my apologies for not trying this sooner. Unfortunately, this isn't working for me. It is only returning articles but it is returning results from all three of my blogs 'recipes 'stories' and 'events. 

 

Do you or anyone else have any additional thoughts on how to achieve this?

ijw
Shopify Partner
11 0 2

Just to clarify ... this code is returning articles ONLY but not only articles from STORIES

 

 

  <input type="text"
        placeholder="Search stories"
        name="q"
        value="{{ search.terms | escape }}"
      />

      <input type="hidden" name="type" value="article" />
      <input type="hidden" name="options[prefix]" value="last" />
      <input type="hidden" name="blog" value="Stories" /> <!-- Specify the blog name here --> 
      <input type="image" name="submit" class="search-submit" src="{{ 'search.svg'| asset_url }}"/>

 

nhcon
Shopify Partner
14 0 7

Did you ever figure this out?

ijw
Shopify Partner
11 0 2

No, I did not. As far as I know, Shopify won't accept that name/value in for the search form. I'm not sure why @NomtechSolution suggested it. The documentation does not have a "blog" as an option. 

alicanteallan7
Shopify Partner
12 0 6

Same here

takahirotakeuch
Shopify Partner
2 0 0

Hello, has the above case been open for a year or so since then, and have you found an effective solution?

Takahiro Takeuchi | TMC Inc.