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

# 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
