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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/frontend-filters/taxonomy-filters/how-to-automatically-check-select-filter-values-based-on-the-archive-page.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
