> For the complete documentation index, see [llms.txt](https://knowledgebase.ajaxsearchpro.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://knowledgebase.ajaxsearchpro.com/frontend-filters/taxonomy-filters/how-to-automatically-check-select-filter-values-based-on-the-archive-page.md).

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

![Category archive auto-selection](/files/-M9vxH3LBufdC5XXPQ_V)

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

```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?](/safe-coding-guideline.md)

```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 %}
