diff --git a/aurweb/routers/packages.py b/aurweb/routers/packages.py
index d4e85d20..34c09d86 100644
--- a/aurweb/routers/packages.py
+++ b/aurweb/routers/packages.py
@@ -40,7 +40,7 @@ async def packages_get(request: Request, context: Dict[str, Any],
search_by = context["SeB"] = request.query_params.get("SeB", "nd")
# Query sort by.
- sort_by = context["SB"] = request.query_params.get("SB", "p")
+ sort_by = request.query_params.get("SB", None)
# Query sort order.
sort_order = request.query_params.get("SO", None)
@@ -93,13 +93,6 @@ async def packages_get(request: Request, context: Dict[str, Any],
# Apply user-specified specified sort column and ordering.
search.sort_by(sort_by, sort_order)
- # If no SO was given, default the context SO to 'a' (Ascending).
- # By default, if no SO is given, the search should sort by 'd'
- # (Descending), but display "Ascending" for the Sort order select.
- if sort_order is None:
- sort_order = "a"
- context["SO"] = sort_order
-
# Insert search results into the context.
results = search.results().with_entities(
models.Package.ID,
diff --git a/templates/partials/packages/search.html b/templates/partials/packages/search.html
index 33bc6132..3db5c7a4 100644
--- a/templates/partials/packages/search.html
+++ b/templates/partials/packages/search.html
@@ -34,6 +34,9 @@
+ {% if not SB %}
+ {% set SB = 'p' %}
+ {% endif %}
+ {% if not SO %}
+ {% set SO = 'd' %}
+ {% endif %}