> 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/displaying-taxonomy-name-in-taxonomy-term-results.md).

# Displaying taxonomy name in taxonomy term results

This custom code is to display the taxonomy name along with the term results.<br>

![](/files/UamcMoNdJvya87mq4ZBN)

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

```php
add_filter('asp_results', 'asp_display_tax_name_in_results');
function asp_display_tax_name_in_results($results) {
	// Change these variables according to the comments after
	$position = 'before'; 	// 'before' or 'after'
	$field = 'title';		// 'title' or 'content'
	$delimiter = ' - '; 	// Characters between the taxonomy name and the field

	// --- DO NOT CHANGER ANYTHING BELOW ---
	foreach($results as $k=>&$r){
		if ( $r->content_type == 'term' ) {
			$taxonomy = get_taxonomy( $r->taxonomy );
			if ( !is_wp_error($taxonomy) ) {
				if ( $field == 'title' ) {
					$f = &$r->title;
				} else {
					$f = &$r->content;
				}
				if ( $position == 'before' ) {
					$f = $taxonomy->labels->name  . $delimiter . $f;
				} else {
					$f .= $delimiter . $taxonomy->labels->name;
				}
				}
			}
	}
	return $results;
}
```

#### Variable to change in the code

* **$position** (line 4) - 'before' or 'after', where you need to display the taxonomy name
* **$field** (line 5) - The field name, 'title' or 'content'
* **$delimiter** (line 6) - String, which is placed between the taxonomy name and the field
