Get active metafield value for dropdown selected

I have added metafields for products and then via the collection page created custom filters which work:

{%- for filter in collection.filters -%}
    
    

      

      
    

  {%- endfor -%}

Which creates nice custom filtering:

When a user chooses a drop down item/filter it redirects the user to a page like:

/collections/shop?filter.p.m.custom.categories=Knitwear

But I can’t work out how to extract the active filter (filter.p.m.custom.categories) value (Knitwear) or get the URL GET param in order to set the dropdown default (selected) value so that the dropdown shows the active filter in place.

I would prefer to do in liquid if possible? or do I have to use JavaScript to sort?