Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
How do you amend the default sort-by for the search results page?
Have attempted to change the data-default-sortby value in sections/search-page.liquid but it makes no difference
<div class="filters-toolbar__input-wrapper select-group">
<select name="sort_by" id="SortBy"
class="filters-toolbar__input"
aria-describedby="a11y-refresh-page-message a11y-selection-message"
data-default-sortby="Featured"
data-select-input
>
{%- for option in collections['all'].sort_options -%}
<option value="{{ option.value }}" {% if option.value == 'manual' %}selected="selected"{% endif %}>{{ option.name }}</option>
{%- endfor -%}
</select>
@WSW wrote:How do you amend the default sort-by for the search results page?
Have attempted to change the data-default-sortby value in sections/search-page.liquid but it makes no difference
<div class="filters-toolbar__input-wrapper select-group">
<select name="sort_by" id="SortBy"
class="filters-toolbar__input"
aria-describedby="a11y-refresh-page-message a11y-selection-message"
data-default-sortby="Featured"
data-select-input
>
{%- for option in collections['all'].sort_options -%}
<option value="{{ option.value }}" {% if option.value == 'manual' %}selected="selected"{% endif %}>{{ option.name }}</option>
{%- endfor -%}
</select>
To amend the default sort-by on your search results page, modify the sections/search-page.liquid file. Instead of changing data-default-sortby, directly set the selected attribute within the for loop to the desired sort option. For example:
{% for option in collections['all'].sort_options %}
<option value="{{ option.value }}" {% if option.value == 'your_desired_default_sort' %}selected="selected"{% endif %}>{{ option.name }}</option>
{% endfor %}
Replace 'your_desired_default_sort' with the desired sort option (e.g., 'featured', 'newest'). This will ensure the correct option is selected by default.
Changing 'your_desired_default_sort' makes no difference to the search results as the default remains Featured
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025