# 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


---

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