# Limiting taxonomy term results to specific term IDs only

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

```php
add_filter('asp_term_query_add_where', 'asp_term_query_add_where_include', 10, 3);
function asp_term_query_add_where_include($args, $s, $s_arr) {
	$ids = '1, 2, 3, 4';  // Enter the taxonomy term IDs here to include

	// -- DO NOT CHANGE BELOW THIS LINE --
	global $wpdb;
	$ids = explode(',', $ids);
	foreach ( $ids as $k => &$id ) {
		$id = trim($id);
		if ( $id == '' ) {
			unset($ids[$k]);
		}
	}
	if ( count($ids) > 0 ) {
	  return " AND ($wpdb->terms.term_id IN (" .implode(",", $ids). "))";
	}

	return '';
}
```

* **$ids** - comma separated list of taxonomy term IDs to restrict the results to


---

# 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/miscellaneous/taxonomy-terms/limiting-taxonomy-term-results-to-specific-term-ids-only.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.
