Why does my product search page have strange formatting?

Topic summary

A Shopify store owner is experiencing pagination issues when filtering search results to show only products tagged “RETAIL”. While the filter successfully displays only the intended products, the pagination formatting is broken—some products appear alone on pages when previous pages should have room for them (visible on pages 3-4).

Root cause identified:
The code loops through search.results and uses an if condition to check for the “RETAIL” tag, which skips non-matching products but doesn’t adjust the pagination count. This causes the paginator to still register skipped items, creating empty spaces and incorrect page breaks.

Recommended solution:
Loop through the already-created retail_results filter instead of search.results, eliminating the need for the conditional check. This should properly reorganize items across pages and fix the formatting issues.

Summarized with AI on November 12. AI used: claude-sonnet-4-5-20250929.

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.