> 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/miscellaneous/post-types/searching-within-given-categories-taxonomy-terms-only.md).

# Searching within given categories/taxonomy terms only

## Solution #1 - via options (easy)

There is an option to restrict results to terms in the plugin back-end. Please check [this documentation](https://documentation.ajaxsearchpro.com/advanced-options/excluding-and-including-results/include-by-categories-or-terms).

## Solution #2 - Programatical restriction via custom code

For more advanced restrictions you can use the [asp\_query\_args](/hooks/filters/query-and-output/asp_query_args.md) filter.

```php
add_filter( 'asp_query_args', 'asp_include_only_term_ids', 2, 2 );
  
function asp_include_only_term_ids( $args, $id ) {
  /**
   * Enter the desired taxonomy=>terms here.
   * For example, if you want to search category 1 and 2, then:
   *  "category" => "1,2"      
   */      
  $include = array(
    "category" => "1,2,3,4",
    "post_tag" => "4,5,6,7"
  );
  // Allow results, that does not have connection with the taxonomies
  $allow_empty = true;
  
  // -- !! Do not change anything below this line !! --
  if ( !is_array($args['post_tax_filter']) )
    $args['post_tax_filter'] = array();
    
  foreach ($include as $tax => $term_string) {
    $terms = explode(",", $term_string);
    foreach ($terms as $tk => &$tv)
      $tv = trim($tv);
    
    $args['post_tax_filter'][] = array(
      'taxonomy'  => $tax,
      'include'   => $terms
    );
  }
  
  return $args;
}
```
