I am working on making my shopify search only show products that are tagged “Retail”
When I complete a search, it is now only showing those products but it has strange formatting, and some products end up on a page by themself when the previous should still have room to show it. See page 3 and 4 - Search: 25 results found for “Motion Unisuit” – 776BC
The code is below.
{%- if search.performed -%}
{%- assign retail_results = search.results | where: “tags”, “RETAIL” | reverse -%}
{%- if search.results_count == 0 -%}
{{ 'general.search.no_results_title_html' | t }}
{{ 'general.search.no_results_html' | t }} '{{ search.terms }}'
{%- else -%}
{{ 'general.search.results_title' | t }} "{{ search.terms }}" ({{ search.results_count }})
{%- paginate search.results by 8 -%}
{%- for item in search.results -%}{%- assign product = item -%}
{%- if product.tags contains 'RETAIL' -%}
{%- include "product-grid-item" -%}
{%- endif -%}
{%- endfor -%}
{%- if paginate.pages > 1 -%}{%- include 'pagination' -%}{%- endif -%}
{%- endpaginate -%}
{%- endif -%}
{%- else -%}
{{ 'general.search.no_results_title_html' | t }}
{%- endif -%}
Hey @Rob776BC ,
You’ve already created the retail_results filter, shouldn’t you loop through that instead? Then you don’t need the if condition again to check if the product tags contain the ‘RETAIL’ tag.
If you loop through the normal search.results, and check if product tags contains ‘RESULTS’ then it’s skipping the ones that don’t but still it registers what page those skipped ones should be in. So the ones that have the filter will still go to the original pages.
I haven’t tested the code, but I can guarantee the issue is because you are just using a if condition to skip items but they are not necessarily re-arranged to new pages, it only skips.