# How to automatically check/select filter values based on the archive page?

![Category archive auto-selection](https://1744076133-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M9rmHbZfTKVQ7YzbIZL%2F-M9vwSzz35JL5ZQxNlw_%2F-M9vxH3LBufdC5XXPQ_V%2Fimage.png?alt=media\&token=a586f844-75c2-4a4c-9f03-fb794a36b44e)

{% tabs %}
{% tab title="For every taxonomy" %}
[Where do I put this custom code?](https://knowledgebase.ajaxsearchpro.com/safe-coding-guideline)

```php
add_filter('asp_pre_get_front_filters', 'asp_change_tax_filter', 10, 2);
function asp_change_tax_filter($filters, $type) {
  // --- DO NOT CHANGE ANYTHING BELOW ---
  if ( is_archive() ) {
      $term_id = get_queried_object()->term_id;
      if ( empty($term_id) )
          return $filters;
          
      $taxonomy = get_queried_object()->taxonomy;   
      foreach ($filters as $k => &$filter) {
          $term_id = get_queried_object()->term_id;
          if ( $type == 'taxonomy' && $filter->data['taxonomy'] == $taxonomy ) {
              $filter->unselect();
              $filter->select($term_id);
          }
      }
  }
  return $filters;
}
```

{% endtab %}

{% tab title="For specific taxonomies only" %}
[Where do I put this custom code?](https://knowledgebase.ajaxsearchpro.com/safe-coding-guideline)

```php
add_filter('asp_pre_get_front_filters', 'asp_change_tax_filter', 10, 2);
function asp_change_tax_filter($filters, $type) {
  $taxonomies = 'category, post_tag'; // Comma separated list of taxonomies

  // --- DO NOT CHANGE ANYTHING BELOW ---
  if ( is_archive() ) {
      $term_id = get_queried_object()->term_id;
      if ( empty($term_id) )
          return $filters;
      $taxonomies = explode(',', $taxonomies);
      foreach ( $taxonomies as $taxonomy ) {
          $taxonomy = trim($taxonomy);
          foreach ($filters as $k => &$filter) {
              if ($type == 'taxonomy' && $filter->data['taxonomy'] == $taxonomy) {
                  $filter->unselect();
                  $filter->select($term_id);
              }
          }
      }
  }
  return $filters;
}
```

* **$taxonomy** (string) - comma separated list of taxonomy names, where you want the code to apply
  {% endtab %}
  {% endtabs %}
